httpclient接口调用
来源:互联网 发布:深圳二手房交易数据 编辑:程序博客网 时间:2024/04/23 21:41
public static String doPost(String url, NameValuePair[] params,
String charset, boolean pretty) {
StringBuffer response = new StringBuffer();
HttpClient client = new HttpClient();
String proxyHost = "192.168.19.9";
int proxyPort = 80;
String userName = "yellowpage\\yellowpage_jpsc";
String password = "abcd_123";
/*
client.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort),
new UsernamePasswordCredentials(userName, password));
HttpHost proxy = new HttpHost(proxyHost,proxyPort);
client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
*/
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
client.getParams().setAuthenticationPreemptive(true);
//如果代理需要密码验证,这里设置用户名密码
client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName,password));
PostMethod method = new PostMethod(url);
// 设置Http Post数据
if (params != null) {
// HttpMethodParams p = new HttpMethodParams();
// for (Map.Entry<String, String> entry : params.entrySet()) {
// p.setParameter(entry.getKey(), entry.getValue());
//
// }
method.setRequestBody(params);
}
try {
client.executeMethod(method);
log.info("http response status code: " + method.getStatusCode());
if (method.getStatusCode() == HttpStatus.SC_OK) {
BufferedReader reader = new BufferedReader(
new InputStreamReader(method.getResponseBodyAsStream(),
charset));
String line;
while ((line = reader.readLine()) != null) {
if (pretty)
response.append(line).append(System.getProperty("line.separator"));
else
response.append(line);
}
reader.close();
}
} catch (IOException e) {
log.error(
"request url exception: " + url + " params: {" + params != null ? params
.toString() : "" + "}", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
String charset, boolean pretty) {
StringBuffer response = new StringBuffer();
HttpClient client = new HttpClient();
String proxyHost = "192.168.19.9";
int proxyPort = 80;
String userName = "yellowpage\\yellowpage_jpsc";
String password = "abcd_123";
/*
client.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort),
new UsernamePasswordCredentials(userName, password));
HttpHost proxy = new HttpHost(proxyHost,proxyPort);
client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
*/
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
client.getParams().setAuthenticationPreemptive(true);
//如果代理需要密码验证,这里设置用户名密码
client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName,password));
PostMethod method = new PostMethod(url);
// 设置Http Post数据
if (params != null) {
// HttpMethodParams p = new HttpMethodParams();
// for (Map.Entry<String, String> entry : params.entrySet()) {
// p.setParameter(entry.getKey(), entry.getValue());
//
// }
method.setRequestBody(params);
}
try {
client.executeMethod(method);
log.info("http response status code: " + method.getStatusCode());
if (method.getStatusCode() == HttpStatus.SC_OK) {
BufferedReader reader = new BufferedReader(
new InputStreamReader(method.getResponseBodyAsStream(),
charset));
String line;
while ((line = reader.readLine()) != null) {
if (pretty)
response.append(line).append(System.getProperty("line.separator"));
else
response.append(line);
}
reader.close();
}
} catch (IOException e) {
log.error(
"request url exception: " + url + " params: {" + params != null ? params
.toString() : "" + "}", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
0 0
- HttpClient调用接口
- httpclient接口调用
- httpclient http接口调用
- httpClient 接口调用
- httpClient接口调用
- java使用httpClient调用接口
- westful httpclient dopost调用接口
- 使用httpclient实现http接口调用实例
- 使用httpclient实现http接口调用实例
- 使用 httpClient 调用新浪微博接口
- java HttpClient get post请求 调用接口
- 使用httpclient实现http接口调用实例
- spring集成httpclient调用远端接口
- 关于HttpClient(调用openstack rest接口失败)
- httpClient发送get请求调用接口
- 使用httpclient实现http接口调用实例
- Apache HttpClient 实现 Java 调用 Http 接口
- JAVA利用HttpClient进行HTTPS接口调用
- 外网登陆SAP的两种方式
- android使用ant编译APK
- SOA——面向服务的体系架构
- ORA-01591: 锁被有问题的分布式事务处理 4.22.2389 持有
- sp_addlinkedserver 与 sp_addlinkedsrvlogin 的用法
- httpclient接口调用
- 使用VC++获取文件路径,已获取当前路径为基础
- Windows下 修改 GRUB背景图片(xpm.gz)
- Android开发:对VA文件根据时间点截取关键帧并转化为Bitmap
- Java Web 程序员的职业进阶之路
- C/C++获取当前系统时间
- 2014中国飞思卡尔技术论坛即将开幕
- OpenCV编程->对比直方图
- DG部署(主库rac)--rman 异机恢复方式