httpclient 中文 教程

上一篇 / 下一篇  2012-08-27 16:06:06 / 个人分类:java

httpclient教程  见附件
 具体我使用的是
public  String getJsonByUrl(String url) {
HttpClient htpc = new HttpClient();
GetMethod getMethod = new GetMethod(url);
try {
int statusCode = htpc.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("methodfailed" + getMethod.getStatusLine());
}
byte[] responseBody = getMethod.getResponseBody();
String s=new String(responseBody);
s = s.replace("public", "_public");
s = s.replace("\n", "");
return s;
} catch (HttpException e) {
System.out.println(e.getMessage());

} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
getMethod.releaseConnection();
}
return "";
}


TAG:

在路上™ 引用 删除 oxygen001   /   2017-04-06 15:18:31
3
 

评分:0

我来说两句

Open Toolbar