关于HttpClient 为什么访问外网就不行呢,抛出异常,说是连接被拒绝,多谢各位 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码如下// 实例化一个HttpClient HttpClient httpClient = new DefaultHttpClient(); // 设定目标站点 HttpHost proxy = new HttpHost("mail.cdpcb.com", 8080); HttpPost post = new HttpPost("http://www.google.com"); // 设置代理对象 ip/代理名称,端口 // 对HttpClient对象设置代理 httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); // HttpGet httpGet = new HttpGet("/"); // 这里也可以直接使用httpGet的绝对地址,当然如果不是具体地址不要忘记/结尾 // HttpGet httpGet = new HttpGet("http://www.shanhe114.com/"); // HttpResponse response = httpClient.execute(httpGet); HttpResponse response = httpClient.execute(post); if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { // 请求成功 // 取得请求内容 HttpEntity entity = response.getEntity(); // 显示内容 if (entity != null) { // 显示结果 BufferedReader reader = new BufferedReader( new InputStreamReader(entity.getContent(), "UTF-8")); String line = null; StringBuffer strBuf = new StringBuffer((int) entity .getContentLength()); while ((line = reader.readLine()) != null) { strBuf.append(line); } strBuf.trimToSize(); System.out.println(strBuf.toString()); } if (entity != null) { entity.consumeContent(); } }else{ System.out.println("资源请求失败"); }我用的是代码,可是还是请求失败,代理也设置了 删除操作如何改用hibernate的hql? 空白页面是什么意思!!! spring packagesToScan问题 求科普,hibernate怎样操作mongodb? 请大侠们救命!急用!! 请问如何能实现这个功能? 如何在点击按钮后在当前页弹出提示框? 自动跳转功能。 Jsp中输出价格的问题!? JAVA中有无函数可以将旧字符串替换成新的字符串?? 关于Syntax error on tokens, delete these tokens错误,大家帮帮忙!!谢谢 小弟求问题答案..........
HttpClient httpClient = new DefaultHttpClient();
// 设定目标站点
HttpHost proxy = new HttpHost("mail.cdpcb.com", 8080);
HttpPost post = new HttpPost("http://www.google.com");
// 设置代理对象 ip/代理名称,端口
// 对HttpClient对象设置代理
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy); // HttpGet httpGet = new HttpGet("/");
// 这里也可以直接使用httpGet的绝对地址,当然如果不是具体地址不要忘记/结尾
// HttpGet httpGet = new HttpGet("http://www.shanhe114.com/");
// HttpResponse response = httpClient.execute(httpGet); HttpResponse response = httpClient.execute(post);
if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {
// 请求成功
// 取得请求内容
HttpEntity entity = response.getEntity();
// 显示内容
if (entity != null) {
// 显示结果
BufferedReader reader = new BufferedReader(
new InputStreamReader(entity.getContent(), "UTF-8"));
String line = null;
StringBuffer strBuf = new StringBuffer((int) entity
.getContentLength());
while ((line = reader.readLine()) != null) {
strBuf.append(line);
}
strBuf.trimToSize();
System.out.println(strBuf.toString());
}
if (entity != null) {
entity.consumeContent();
}
}else{
System.out.println("资源请求失败");
}
我用的是代码,可是还是请求失败,代理也设置了