title: https proxy with JDK11 client
body: <p>I'd like to use the JDK 11 <code>HttpClient</code> to perform a request through an HTTPS proxy. I've tried this code to create the client:</p>
  <pre class="lang-java prettyprint-override"><code>HttpClient client = HttpClient
      .newBuilder()
      .proxy(ProxySelector.of(new InetSocketAddress(&quot;my.proxy.host&quot;,8443)))
      .version(Version.HTTP_1_1)
      .build();
  </code></pre>
  <p>and this code to generate the request:</p>
  <pre class="lang-java prettyprint-override"><code>String auth = new String(Base64.getEncoder().encode(&quot;username:password&quot;.getBytes()));
  var request =
  HttpRequest
      .newBuilder(new URI(&quot;http://my.internal.host/path&quot;))
      .POST(BodyPublishers.ofString(&quot;{\&quot;foo\&quot;:\&quot;bar\&quot;}&quot;))
      .header(&quot;Proxy-Authorization&quot;, &quot;Basic &quot; + auth)
      .header(&quot;Content-Type&quot;, &quot;application/json&quot;)
      .build();
  </code></pre>
  <p>But it fails with <code>java.io.IOException: HTTP/1.1 header parser received no bytes</code>.</p>
  <p>The equivalent <code>curl</code> I'd like to perform would be:</p>
  <pre class="lang-sh prettyprint-override"><code>curl -XPOST --proxy 'https://username:password@http://my.proxy.host:8443/path' \
    -d '{&quot;foo&quot;:&quot;bar&quot;}' \
    -h 'Content-Type: application/json' \
    http://my.internal.host/path
  </code></pre>
  <p>And that works. Any suggestions?</p>