Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpClient 4.2.2 and proxy with username/password
    primarykey
    data
    text
    <p>I have a problem with HttpClient 4.2.2 and proxy with username/password. HttpClient works in this way:</p> <ol> <li>List item</li> <li>Send request without proxy stuff (however I set proxy parameters for each request)</li> <li>Get response from Squid with 407 error</li> <li>Send request with proxy stuff</li> </ol> <p>It's very strange behavior, Is it possible to add info about proxy to each request? I've tried to add hardcoded "Proxy-Authorization" header to each request and it works fine, why HttpClient can't do the same?</p> <p><strong>Java code</strong></p> <pre><code>DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(PROTOCOL_VERSION, HTTP_1_1); ... String proxyServer = getProxyServer(); int proxyPort = getProxyPort(); List&lt;String&gt; authpref = new ArrayList&lt;String&gt;(); authpref.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); String proxyUser = getProxyUser(); String proxyPassword = getProxyPassword(); CredentialsProvider credsProvider = httpClient.getCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyServer, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword)); httpClient.setCredentialsProvider(credsProvider); HttpHost proxy = new HttpHost(proxyServer, proxyPort, (proxyServer.indexOf("https") != 0) ? "http" : "https"); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); ... HttpPut put = new HttpPut(url); /*** hardcoded header ***/ //put.addHeader("Proxy-Authorization", "Basic eHRlbmR4LmRuZXByOnF3ZXJ0eQ=="); /*** hardcoded header ***/ put.setEntity(entity); httpClient.execute(put); httpClient.getConnectionManager().shutdown(); [DefaultClientConnection] Sending request: PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image1.jpg HTTP/1.1 [headers] &gt;&gt; PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image1.jpg HTTP/1.1 [headers] &gt;&gt; Authorization: Basic eGRldjo0YTFmNmMwOTgyYWRkMWQ0NDg1YjRhMGE4YWMxY2JjMWNiMTA0ODc1 [headers] &gt;&gt; Content-Length: 2 [headers] &gt;&gt; Host: 172.26.27.22:8080 [headers] &gt;&gt; Proxy-Connection: Keep-Alive [headers] &gt;&gt; User-Agent: Apache-HttpClient/4.2.2 (java 1.5) [DefaultClientConnection] Receiving response: HTTP/1.0 407 Proxy Authentication Required [headers] &lt;&lt; HTTP/1.0 407 Proxy Authentication Required [headers] &lt;&lt; Server: squid/2.7.STABLE8 [headers] &lt;&lt; Date: Thu, 08 Nov 2012 10:09:49 GMT [headers] &lt;&lt; Content-Type: text/html [headers] &lt;&lt; Content-Length: 1431 [headers] &lt;&lt; X-Squid-Error: ERR_CACHE_ACCESS_DENIED 0 [headers] &lt;&lt; Proxy-Authenticate: Basic realm="Please, enter username and password" [headers] &lt;&lt; X-Cache: MISS from 172.26.27.94 [headers] &lt;&lt; X-Cache-Lookup: NONE from 172.26.27.94:3128 [headers] &lt;&lt; Via: 1.0 172.26.27.94:3128 (squid/2.7.STABLE8) [headers] &lt;&lt; Connection: close [DefaultHttpClient] Authentication required [DefaultHttpClient] 172.26.27.94:3128 requested authentication [ProxyAuthenticationStrategy] Authentication schemes in the order of preference: [Basic] [DefaultHttpClient] Selected authentication options: [BASIC] [DefaultClientConnection] Connection 0.0.0.0:63344&lt;-&gt;172.26.27.94:3128 closed [DefaultClientConnectionOperator] Connecting to 172.26.27.94:3128 [RequestAddCookies] CookieSpec selected: best-match [RequestAuthCache] Re-using cached 'basic' auth scheme for http://172.26.27.22:8080 [RequestAuthCache] No credentials for preemptive authentication [RequestProxyAuthentication] Proxy auth state: CHALLENGED [RequestProxyAuthentication] Generating response to an authentication challenge using basic scheme [DefaultHttpClient] Attempt 2 to execute request [DefaultClientConnection] Sending request: PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image1.jpg HTTP/1.1 [headers] &gt;&gt; PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image1.jpg HTTP/1.1 [headers] &gt;&gt; Authorization: Basic eGRldjo0YTFmNmMwOTgyYWRkMWQ0NDg1YjRhMGE4YWMxY2JjMWNiMTA0ODc1 [headers] &gt;&gt; Content-Length: 2 [headers] &gt;&gt; Host: 172.26.27.22:8080 [headers] &gt;&gt; Proxy-Connection: Keep-Alive [headers] &gt;&gt; User-Agent: Apache-HttpClient/4.2.2 (java 1.5) [headers] &gt;&gt; Proxy-Authorization: Basic eHRlbmR4LmRuZXByOnF3ZXJ0eQ== [DefaultClientConnection] Receiving response: HTTP/1.0 201 Created [headers] &lt;&lt; HTTP/1.0 201 Created [headers] &lt;&lt; Content-Length: 0 [headers] &lt;&lt; Date: Thu, 08 Nov 2012 10:09:49 GMT [headers] &lt;&lt; X-Cache: MISS from 172.26.27.94 [headers] &lt;&lt; X-Cache-Lookup: MISS from 172.26.27.94:3128 [headers] &lt;&lt; Via: 1.1 172.26.27.94:3128 (squid/2.7.STABLE8) [headers] &lt;&lt; Connection: keep-alive [headers] &lt;&lt; Proxy-Connection: keep-alive </code></pre> <p><em>Squid log</em></p> <pre><code>1352370666.778 0 172.26.27.94 TCP_DENIED/407 1870 PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image1.jpg - NONE/- text/html 1352370671.429 8 172.26.27.94 TCP_MISS/201 282 PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image1.jpg proxyuser DIRECT/172.26.27.22 - 1352370671.474 0 172.26.27.94 TCP_DENIED/407 1882 PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image2.jpg - NONE/- text/html 1352370671.486 7 172.26.27.94 TCP_MISS/201 282 PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image2.jpg proxyuser DIRECT/172.26.27.22 - </code></pre> <p><strong>With hardcoded header</strong></p> <p>There is no 407 error in the java log, and squid log</p> <p><em>Squid log</em></p> <pre><code>1352370542.016 8 172.26.27.94 TCP_MISS/201 282 PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image1.jpg proxyuser DIRECT/172.26.27.22 - 1352370542.033 7 172.26.27.94 TCP_MISS/201 282 PUT http://172.26.27.22:8080/myapp/rest/2/3/29/image2.jpg proxyuser DIRECT/172.26.27.22 - </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload