Skip to content

Instantly share code, notes, and snippets.

@precious-ming
Created September 20, 2014 08:09
Show Gist options
  • Save precious-ming/bd18ec094b46f2a2c8f6 to your computer and use it in GitHub Desktop.
Save precious-ming/bd18ec094b46f2a2c8f6 to your computer and use it in GitHub Desktop.
HTTP client的使用
HttpClient client = null;
try {
client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://www.youdao.com/smartresult-xml/search.s?type=id&q="+code);
HttpResponse response = client.execute(get);
InputStream stream = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream,"GBK"));
StringBuilder sb = new StringBuilder();
String str = null;
while((str = reader.readLine()) != null) {
sb.append(str);
}
reader.close();
stream.close();
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(client != null)
client.getConnectionManager().shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment