httpclient4 设置代理返回页面信息socket closed
httpclient4做sina微博模拟登录,访问状态是200成功,但是返回页面信息时。inputstream.read()一直是socketclosed。实在是不知道怎...
httpclient4做sina微博模拟登录,访问状态是200成功,但是返回页面信息时。inputstream.read()一直是socket closed 。实在是不知道怎么做了,纠结一天了。
求高手们解答,代理,超时都已经设定
public void init(){
HttpHost proxy = new HttpHost("202.149.69.125", 8080);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 60000);
HttpConnectionParams.setSoTimeout(httpClient.getParams(), 60000);
HttpClientParams.setCookiePolicy(httpClient.getParams(),CookiePolicy.BROWSER_COMPATIBILITY);
}
HttpResponse response = null;
UrlEncodedFormEntity params = new UrlEncodedFormEntity(qparams, "UTF-8");
try {
httpost.setEntity(params);
response = httpClient.execute(httpost);
} catch (Exception e) {
e.printStackTrace();
return "";
} finally {
httpost.abort();
}
// 取得登陆第一次正文
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new GZIPInputStream(inputStream),"GBK"));
StringBuffer sBuffer = new StringBuffer();
String s = "";
while ((s=bufferedReader.readLine())!=null) {
sBuffer.append(s);
}
String content = sBuffer.toString(); 展开
求高手们解答,代理,超时都已经设定
public void init(){
HttpHost proxy = new HttpHost("202.149.69.125", 8080);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 60000);
HttpConnectionParams.setSoTimeout(httpClient.getParams(), 60000);
HttpClientParams.setCookiePolicy(httpClient.getParams(),CookiePolicy.BROWSER_COMPATIBILITY);
}
HttpResponse response = null;
UrlEncodedFormEntity params = new UrlEncodedFormEntity(qparams, "UTF-8");
try {
httpost.setEntity(params);
response = httpClient.execute(httpost);
} catch (Exception e) {
e.printStackTrace();
return "";
} finally {
httpost.abort();
}
// 取得登陆第一次正文
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new GZIPInputStream(inputStream),"GBK"));
StringBuffer sBuffer = new StringBuffer();
String s = "";
while ((s=bufferedReader.readLine())!=null) {
sBuffer.append(s);
}
String content = sBuffer.toString(); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询