当前位置: 代码迷 >> Web前端 >> web server 中设立wifi代理
  详细解决方案

web server 中设立wifi代理

热度:94   发布时间:2012-10-19 16:53:37.0
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); //从服务器返回的结果
  相关解决方案