Android HttpClient Doesn't Use System Proxy Settings

前端 未结 4 869
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 01:36

When I create a DefaultHttpClient object and try to hit a webpage, the request isn\'t routed through the proxy I specified in Settings.

Looking through the API docs,

4条回答
  •  旧巷少年郎
    2020-12-05 02:03

    Try :

    System.setProperty("http.proxyHost", );
    System.setProperty("http.proxyPort", );
    

    or

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpHost httpproxy = new HttpHost("",);
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,  httpproxy);
    

    or

    HttpHost proxy = new HttpHost("ip address",port number);  
    DefaultHttpClient httpclient = new DefaultHttpClient(); 
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
    
    HttpPost httpost = new HttpPost(url);
    List nvps = new ArrayList();
    nvps.add(new BasicNameValuePair("param name", param));
    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.ISO_8859_1));
    HttpResponse response = httpclient.execute(httpost);
    
    HttpEntity entity = response.getEntity(); 
    System.out.println("Request Handled?: " + response.getStatusLine());
    InputStream in = entity.getContent();
    httpclient.getConnectionManager().shutdown();
    

提交回复
热议问题