title: Apache HTTP Client 5.0 HTTP/2 POST Example needed
body: <p>I can use CURL to send a HTTP/2 POST request with a payload to the <code>https://httpbin.org/post</code> as in the following example:</p>
  <pre><code>&quot;c:\Program Files\Git\mingw64\bin\curl&quot; -v --http2 https://httpbin.org/post -d &quot;arg1=param1&amp;arg2=param2&quot;
  *   Trying 54.166.163.67:443...
  * Connected to httpbin.org (54.166.163.67) port 443 (#0)
  * ALPN, offering h2
  * ALPN, offering http/1.1
  * successfully set certificate verify locations:
  *  CAfile: c:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
  *  CApath: none
  * TLSv1.3 (OUT), TLS handshake, Client hello (1):
  * TLSv1.3 (IN), TLS handshake, Server hello (2):
  * TLSv1.2 (IN), TLS handshake, Certificate (11):
  * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  * TLSv1.2 (IN), TLS handshake, Server finished (14):
  * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
  * TLSv1.2 (OUT), TLS handshake, Finished (20):
  * TLSv1.2 (IN), TLS handshake, Finished (20):
  * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
  * ALPN, server accepted to use h2
  * Server certificate:
  *  subject: CN=httpbin.org
  *  start date: Dec 21 00:00:00 2020 GMT
  *  expire date: Jan 19 23:59:59 2022 GMT
  *  subjectAltName: host &quot;httpbin.org&quot; matched cert's &quot;httpbin.org&quot;
  *  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
  *  SSL certificate verify ok.
  * Using HTTP2, server supports multi-use
  * Connection state changed (HTTP/2 confirmed)
  * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
  * Using Stream ID: 1 (easy handle 0x160f6b61d20)
  &gt; POST /post HTTP/2
  &gt; Host: httpbin.org
  &gt; user-agent: curl/7.75.0
  &gt; accept: */*
  &gt; content-length: 23
  &gt; content-type: application/x-www-form-urlencoded
  &gt;
  * Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
  * We are completely uploaded and fine
  &lt; HTTP/2 200
  &lt; date: Fri, 05 Mar 2021 16:07:51 GMT
  &lt; content-type: application/json
  &lt; content-length: 453
  &lt; server: gunicorn/19.9.0
  &lt; access-control-allow-origin: *
  &lt; access-control-allow-credentials: true
  &lt;
  {
    &quot;args&quot;: {},
    &quot;data&quot;: &quot;&quot;,
    &quot;files&quot;: {},
    &quot;form&quot;: {
      &quot;arg1&quot;: &quot;param1&quot;,
      &quot;arg2&quot;: &quot;param2&quot;
    },
    &quot;headers&quot;: {
      &quot;Accept&quot;: &quot;*/*&quot;,
      &quot;Content-Length&quot;: &quot;23&quot;,
      &quot;Content-Type&quot;: &quot;application/x-www-form-urlencoded&quot;,
      &quot;Host&quot;: &quot;httpbin.org&quot;,
      &quot;User-Agent&quot;: &quot;curl/7.75.0&quot;,
      &quot;X-Amzn-Trace-Id&quot;: &quot;Root=1-60425757-45ab281925b9b40e70398269&quot;
    },
    &quot;json&quot;: null,
    &quot;origin&quot;: &quot;51.37.211.242&quot;,
    &quot;url&quot;: &quot;https://httpbin.org/post&quot;
  }
  * Connection #0 to host httpbin.org left intact
  
  </code></pre>
  <p>You can see it sends the arg1/arg2 parameters and they are in the echoed back response.</p>
  <p>I would like to replicate that code in Java. I have had no luck myself doing it and cannot find an example of a HTTP/2 POST <em>with</em> a payload. There are some examples of GET/POST calls using HTTP/2 without a payload, and indeed I can write the code to make a request without a payload that works, but I cannot get the payload to send. If I use the same code but using HTTP/1 the payload is sent. Using <code>BasicRequestProducer</code> class you can give it producers (to send the request data I hope) and consumers (to consume the response) but the producer never seems to send the data.</p>
  <p>See my other question on <a href="https://stackoverflow.com/questions/66477744/how-to-troubleshoot-apache-client-5-0-connection-is-closed-https-post-error">HTTP/2 Connection Closed</a> for the sort of code I am using.</p>
  <p>I have added some DEBUG to my examples and I can see the content/body being added to the request (or at least it looks to me like it is being added) so is there an issue with the correct formatting of the message?</p>
  <pre><code>188  [requester-dispatch-1] DEBUG com.test.HTTP2Tester  - Frame 1 &gt;&gt;[type=0, flags=0, streamId=1, payoad=java.nio.HeapByteBuffer[pos=0 lim=23 cap=23]]
  188  [requester-dispatch-1] DEBUG com.test.HTTP2Tester  - Frame info : Frame 1 &gt;&gt; [type=0, flags=0, streamId=1, payoad=java.nio.HeapByteBuffer[pos=0 lim=23 cap=23]]
  189  [requester-dispatch-1] DEBUG com.test.HTTP2Tester  - stream 1 frame: DATA (0x0); flags: (0x0); length: 23
  189  [requester-dispatch-1] DEBUG com.test.HTTP2Tester  - Frame Payload : Frame 1 &gt;&gt; java.nio.HeapByteBuffer[pos=0 lim=23 cap=23]
  189  [requester-dispatch-1] DEBUG com.test.HTTP2Tester  - Code=99&amp;Message=  43 6f 64 65 3d 39 39 26 4d 65 73 73 61 67 65 3d
  Goodbye           47 6f 6f 64 62 79 65
  
  189  [requester-dispatch-1] DEBUG com.test.HTTP2Tester  - OutputFlow 0 &gt;&gt;0 -23 65512
  190  [requester-dispatch-1] DEBUG com.test.HTTP2Tester  - OutputFlow 1 &gt;&gt;1 -23 65512
  </code></pre>
  <p>Can anyone give Java code to demonstrate a successful HTTP/2 POST with a payload????</p>