httpclient 4.x:407 Proxy Authentication Required

View: New views
2 Messages — Rating Filter:   Alert me  

httpclient 4.x:407 Proxy Authentication Required

by Angelo Chen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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);


Re: httpclient 4.x:407 Proxy Authentication Required

by olegk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jun 24, 2009 at 02:37:26AM -0700, Angelo Chen wrote:

>
> 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,
>

Post wire log:

http://hc.apache.org/httpcomponents-client/logging.html

Oleg


> 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);
>
>
> --
> View this message in context: http://www.nabble.com/httpclient-4.x%3A407-Proxy-Authentication-Required-tp24181617p24181617.html
> Sent from the HttpClient-User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@...
> For additional commands, e-mail: httpclient-users-help@...
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@...
For additional commands, e-mail: httpclient-users-help@...