I am trying to POST some parameters to a server, but I need to set up the proxy. can you help me to to sort it "setting the proxy" part of my code ?
HttpHost proxy = new HttpHost("xx.x.x.xx");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter("3128",proxy);
HttpPost httpost = new HttpPost(url);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("aranan", song));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
System.out.println("Request Handled?: " + response.getStatusLine());
in = entity.getContent();
httpclient.getConnectionManager().shutdown();
This is quick way I use to set the proxy:
When I use apache httpclient v4.5.5,I found HttpClient.getParams() is deprecated in v4.3,we should use
org.apache.http.client.config.RequestConfig
instead. Code sample shows that:Non deprecated way of doing it (also in 4.5.5 version) is:
Yes I sorted out my own problem,this line
should be
Complete Example of a Apache HttpClient 4.1, setting proxy can be found below