httpclient 4.x:407 Proxy Authentication Required
Hi,
I need to use proxy to login to my site, code below works quite well when the setEntity line is commented out, if not then I'm getting this error returning from proxy server:
407 Proxy Authentication Required
any idea what I'm missing here? Thanks,
a.c.
HttpPost httpPost = new HttpPost(loginURL);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("uname", "test"));
nvps.add(new BasicNameValuePair("password", "testpwd"));
this.setProxyInfo(httpclient); // set the proxy info
httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); // !!! comment out this line will remove the message
response = httpclient.execute(httpPost);
private void setProxyInfo(DefaultHttpClient httpClient) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(proxyHost, proxyPort),
new UsernamePasswordCredentials(proxyUserName, proxyPassword));
httpClient.setCredentialsProvider(credsProvider);
HttpHost proxy = new HttpHost(proxyHost, proxyPort, "http");
HttpParams params = httpClient.getParams();
HttpProtocolParams.setUserAgent(params, agent_id);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);