小鱼儿丿 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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制