web server 中设置wifi代理

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpParams httpParams = httpClient.getParams();
httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 6000);
httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 6000);
// 设置代理
String proxyIp = "192.168.81.5"; // 此代理为wifi中设置的代理,获取根据实际情况自行设置
String proxyPort = 80;
if (proxyIp != null && proxyPort != -1) {
HttpHost postProxy = new HttpHost(proxyIp, proxyPort);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, postProxy);  
}

HttpPost httpPost = new HttpPost(serverURL); // 其中serverURL的值根据实际情况自己定义,此处为String类型
httpPost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
HttpResponse httpResponse = httpClient.execute(httpPost); //从服务器返回的结果

猜你喜欢

转载自huangqinqin.iteye.com/blog/1684047