Apache HttpComponents (4.5.2)を使用していて、プロキシサーバー(SSHトンネリング)経由でHTTPSページを要求しようとしています。 ヘッダーなしで、クライアントは最初の要求を送信しますが、Proxyが407エラー(Proxy Authentication Required)で応答した後、Proxy-Authorization
ヘッダーを送信して認証を終了します。Proxy HttpComponentsの最初のリクエスト内でProxy-Authorizationヘッダーが送信されない
私のコードには問題があると思いますが、プリミティブ認証を有効にするようなものが必要ですが、その方法に関する情報は見つかりませんでした。
以下は、自分の言葉を確認するためのログです。
まず要求:
03:12:06,643 DEBUG headers:135 - http-outgoing-0 >> CONNECT t.myhost.com:443 HTTP/1.1
03:12:06,643 DEBUG headers:138 - http-outgoing-0 >> Host: t.myhost.com
03:12:06,643 DEBUG headers:138 - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_45)
03:12:06,793 DEBUG headers:124 - http-outgoing-0 << HTTP/1.1 407 Proxy Authentication Required
03:12:06,794 DEBUG headers:127 - http-outgoing-0 << Proxy-Authenticate: Basic realm="ProxyCompany"
03:12:06,794 DEBUG headers:127 - http-outgoing-0 << Proxy-Connection: close
//それが含まProxy-Authorization
ヘッダ
03:12:06,795 DEBUG HttpAuthenticator:77 - Authentication required
03:12:06,795 DEBUG HttpAuthenticator:107 - 162.243.116.56:71223 requested authentication
03:12:06,795 DEBUG ProxyAuthenticationStrategy:174 - Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, Digest, Basic]
03:12:06,795 DEBUG ProxyAuthenticationStrategy:203 - Challenge for Negotiate authentication scheme not available
03:12:06,796 DEBUG ProxyAuthenticationStrategy:203 - Challenge for Kerberos authentication scheme not available
03:12:06,796 DEBUG ProxyAuthenticationStrategy:203 - Challenge for NTLM authentication scheme not available
03:12:06,796 DEBUG ProxyAuthenticationStrategy:203 - Challenge for Digest authentication scheme not available
03:12:06,800 DEBUG HttpAuthenticator:157 - Selected authentication options: [BASIC [complete=true]]
03:12:06,800 DEBUG DefaultManagedHttpClientConnection:81 - http-outgoing-0: Close connection
03:12:06,801 DEBUG DefaultHttpClientConnectionOperator:138 - Connecting to /162.243.116.56:71223
03:12:06,942 DEBUG DefaultHttpClientConnectionOperator:145 - Connection established 192.168.0.100:13391<->162.243.116.56:71223
03:12:06,942 DEBUG HttpAuthenticator:198 - Generating response to an authentication challenge using basic scheme
03:12:06,947 DEBUG headers:135 - http-outgoing-0 >> CONNECT t.myhost.com:443 HTTP/1.1
03:12:06,947 DEBUG headers:138 - http-outgoing-0 >> Host: t.myhost.com
03:12:06,947 DEBUG headers:138 - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_45)
03:12:06,947 DEBUG headers:138 - http-outgoing-0 >> Proxy-Authorization: Basic bHVtXXXXXXXXXXXXxOTE5NTUXXXXXXRmNmRkYmI1Mjk0MA==
03:12:07,304 DEBUG HttpAuthenticator:86 - Authentication succeeded
03:12:07,305 DEBUG ProxyAuthenticationStrategy:227 - Caching 'basic' auth scheme for http://162.243.116.56:71223
でリクエストを再試行すると、これは私のコード(それはScalaのだが、読みするのは簡単)です:
val credProvider = {
val provider = new BasicCredentialsProvider()
provider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("myUser", "myPass"))
provider
}
val connManager = {
val mngr = new PoolingHttpClientConnectionManager()
mngr.setDefaultMaxPerRoute(Integer.MAX_VALUE)
mngr.setMaxTotal(Integer.MAX_VALUE)
mngr
}
val client = HttpClients.custom()
.setConnectionManager(connManager)
.disableRedirectHandling()
.setDefaultCredentialsProvider(credProvider)
.setProxy(new HttpHost(162.243.116.56, 71223))
.build()
val requestConfig = RequestConfig.custom()
.setConnectTimeout(30000)
.setConnectionRequestTimeout(30000)
.build()
val request = new HttpGet(url)
request.setConfig(requestConfig)
val response = client.execute(request)
どのようにしてこの問題を解決できるのですか(クライアントは常にを送信します210)?
http://stackoverflow.com/questions/2014700/preemptive-basic-authentication-with-apache-httpclient -4?rq = 1(公式だが「落胆」)http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/httpclient/src/examples/org/apache/http /examples/client/ClientPreemptiveBasicAuthentication.javaを呼び出して、いくつかのバリエーションを呼び出し、 '.addHeader'を手動で実行するだけです。 –
私もjava.net.HttpURLConnectionで同じ問題が発生しています。プロトコルがHTTPSの場合、「Proxy-Authorization」ヘッダーは最初の要求では送信されません。その結果、サーバーはHTTP 407で応答します。 – imesh