title: http2 request returning bad request
body: <p>I have a C program of socket which has to use http2 protocol. It is returning Bad Request - HTTP Error 400. The request is badly formed. </p>
  
  <p>Initially, I sent a request like the following through curl 7.64:</p>
  
  <pre><code>curl -v -http2 -i https://mywebsite.xyz 
  </code></pre>
  
  <p>and i got the following output:</p>
  
  <pre><code>* Expire in 0 ms for 6 (transfer 0x55cc25ec95c0)
  * Expire in 1 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 0 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 1 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 0 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 0 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 1 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 0 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 0 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 2 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 1 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 1 ms for 1 (transfer 0x55cc25ec95c0)
  * Expire in 2 ms for 1 (transfer 0x55cc25ec95c0)
  *   Trying 10.8.0.253...
  * TCP_NODELAY set
  * Expire in 200 ms for 4 (transfer 0x55cc25ec95c0)
  * Connected to mysite.xyz (10.8.0.253) port 443 (#0)
  * ALPN, offering h2
  * ALPN, offering http/1.1
  * successfully set certificate verify locations:
  *   CAfile: none
    CApath: /etc/ssl/certs
  * 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-AES256-GCM-SHA384
  * ALPN, server accepted to use h2
  * Server certificate:
  *  subject: C=US; postalCode=XXXX; ST=XX; L=XXXXX; street=XXXXXXXXXXXX; O=XXXXXX; OU=PremiumSSL Wildcard; CN=*.XXXXXXX
  *  start date: Nov 20 00:00:00 2018 GMT
  *  expire date: Feb 21 23:59:59 2021 GMT
  *  subjectAltName: host "mysite.xyz" matched cert's "*.mysite.xyz"
  *  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Organization Validation Secure Server CA
  *  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 0x55cc25ec95c0)
  &gt; GET / HTTP/2
  &gt; Host: mysite.xyz
  &gt; User-Agent: curl/7.64.0
  &gt; Accept: */*
  &gt; 
  * Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
  &lt; HTTP/2 200 
  HTTP/2 200 
  &lt; content-type: text/html
  content-type: text/html
  &lt; last-modified: Mon, 01 Jul 2019 17:57:17 GMT
  last-modified: Mon, 01 Jul 2019 17:57:17 GMT
  &lt; accept-ranges: bytes
  accept-ranges: bytes
  &lt; etag: "c7c5406c3630d51:0"
  etag: "c7c5406c3630d51:0"
  &lt; server: Microsoft-IIS/10.0
  server: Microsoft-IIS/10.0
  &lt; date: Mon, 01 Jul 2019 19:45:53 GMT
  date: Mon, 01 Jul 2019 19:45:53 GMT
  &lt; content-length: 51
  content-length: 51
  
  &lt; 
  &lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;/body&gt;Hello&lt;/body&gt;
  * Connection #0 to host mysite.xyz left intact
  &lt;/html&gt;
  </code></pre>
  
  <p>From the above request-response log, I took the following:</p>
  
  <pre><code>GET / HTTP/2
  Host: mysite.xyz
  User-Agent: curl/7.64.0
  Accept: */*
  </code></pre>
  
  <p>and created a request like the following:</p>
  
  <pre><code>char* inputString = "GET / HTTP/2\r\nHost: mysite.xyz\r\nUser-Agent: curl/7.64.0\r\nAccept: */*\r\n\r\n"
  
  </code></pre>
  
  <p>But, this time I am getting error like:</p>
  
  <pre><code>Connected with ECDHE-RSA-AES256-GCM-SHA384 encryption
  Received: "HTTP/1.1 400 Bad Request
  Content-Type: text/html; charset=us-ascii
  Server: Microsoft-HTTPAPI/2.0
  Date: Mon, 01 Jul 2019 20:28:48 GMT
  Connection: close
  Content-Length: 311
  
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"&gt;
  &lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;Bad Request&lt;/TITLE&gt;
  &lt;META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"&gt;&lt;/HEAD&gt;
  &lt;BODY&gt;&lt;h2&gt;Bad Request&lt;/h2&gt;
  &lt;hr&gt;&lt;p&gt;HTTP Error 400. The request is badly formed.&lt;/p&gt;
  &lt;/BODY&gt;&lt;/HTML&gt;
  </code></pre>