常会遇到状态405错误,因为大多数wed服务器不允许静态文件响应post请求,只需要把post 改为get就可以运行.
public static String givenRedirecting(String pageUrl) throws ClientProtocolException, IOException {
HttpClient instance = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
org.apache.http.HttpResponse response = instance.execute(new HttpGet(pageUrl));
String html = EntityUtils.toString(response.getEntity(), "gbk");
return html;
}
HTTPS 问题
在请求前加上
System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");