Java 代理授权标头未在Apache HttpComponents中的第一个请求内发送

Java 代理授权标头未在Apache HttpComponents中的第一个请求内发送,java,scala,apache-httpclient-4.x,apache-httpcomponents,Java,Scala,Apache Httpclient 4.x,Apache Httpcomponents,我正在使用并试图通过代理服务器(SSH隧道)请求HTTPS页面 问题在于,根据日志,客户端发送第一个请求时没有代理授权头,但在代理响应407错误(需要代理身份验证)后,它会使用发送代理授权头取消身份验证 我认为在我的代码中有一个问题,我需要一些类似于启用原语身份验证的东西,但我找不到任何关于如何做到这一点的信息 下面是确认我的话的日志 第一项请求: 03:12:06,643 DEBUG headers:135 - http-outgoing-0 >> CONNECT t.myhost

我正在使用并试图通过代理服务器(SSH隧道)请求HTTPS页面

问题在于,根据日志,客户端发送第一个请求时没有
代理授权
头,但在代理响应407错误(需要代理身份验证)后,它会使用发送
代理授权
头取消身份验证

我认为在我的代码中有一个问题,我需要一些类似于启用原语身份验证的东西,但我找不到任何关于如何做到这一点的信息

下面是确认我的话的日志

第一项请求:

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
这是我的代码(它是Scala,但很容易阅读):


如何解决此问题(使客户端始终发送
代理授权

我不确定这是否是同一个问题,但在版本4.5.2中,SPN(HTTP)引入了一个bug/something@somerealm)和https:(这些评论特别有趣,因为它们展示了发生的事情的历史)


切换到4.5.1版应该可以解决这个问题(当然,如果这是同一个问题)

我不确定这是否是同一个问题,但在4.5.2版中,SPN(HTTP)引入了一个bug/something@somerealm)和https:(这些评论特别有趣,因为它们展示了发生的事情的历史)


切换到4.5.1版应该可以解决这个问题(当然,如果这是同一个问题)

链接到(官方但“不鼓励”),然后在其上和手动执行
.addHeader
时发出几个变体。我还看到java.net.HttpURLConnection也存在同样的问题。如果协议为HTTPS,则在初始请求中不发送“代理授权”标头。因此,服务器使用HTTP 407进行响应。有什么想法吗?链接到(官方但“不鼓励”),然后在其上和仅执行
.addHeader
manually时响起几个变体。我还发现java.net.HttpURLConnection存在同样的问题。如果协议为HTTPS,则在初始请求中不发送“代理授权”标头。因此,服务器使用HTTP 407进行响应。有什么想法吗?
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 
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)