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.