小鱼儿丿 2017-02-07 02:51 采纳率: 100%
浏览 1116

httpclient 代理 问题

public static void main(String[] args) throws Exception {

    System.out.println(doPost("http://172.21.0.158:8181/ShiroWeb/login"));
}

public static String doPost(String url) throws Exception{
    String result = ""; 
   // 创建HttpClient实例     
   CloseableHttpClient httpclient = HttpClients.createDefault();
   // 创建Post方法实例     
   HttpPost httpPost = new HttpPost(url);
   HttpHost proxy = new HttpHost("180.97.237.199", 8080);
   RequestConfig requestConfig = RequestConfig.custom().setProxy(proxy).build();
   httpPost.setConfig(requestConfig);
   httpPost.setHeader("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
   //执行请求
   CloseableHttpResponse  response = httpclient.execute(httpPost);    
   //返回的请求内容
   HttpEntity entity = response.getEntity(); 
   int statusCode =  response.getStatusLine().getStatusCode();
   if(statusCode == 200){
       result = entity.toString();
   }
return result;

}

用代理访问 www 开头的网站就可以,但是访问自己主机 就不行,因为我想看看一下ip是不是真的变成代理的ip . 。我在自己服务器打了断电并且用request.getr emoteAd dr() ; 获取ip 。 现在问题是这样访问不了 repones 状态吗:504.

  • 写回答

1条回答 默认 最新

  • shen_wei 2017-02-07 09:30
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题