Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C++ HTTP 2 POST request getting rejected

I am trying to simulate this Curl command but only using C++:

curl -H "X-MBX-APIKEY: dummy_one" -X POST 'https://api.binance.com/api/v3/order?hello'

The above request generates this response:

{"code":-2014,"msg":"API-key format invalid."}

Curl’s verbose logging switch shows it sent this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

> POST /api/v3/order?hello HTTP/2
> Host: api.binance.com
> user-agent: curl/7.81.0
> accept: */*
> x-mbx-apikey: dummy_one
> 

This is my attempt in C++:

char* write_buf = "POST /api/v3/order HTTP/2\r\n"
                  "Host: api.binance.com\r\n"
                  "user-agent: curl/7.81.0\r\n"
                  "accept: */*\r\n"
                  "X-MBX-APIKEY: dummy_one\r\n"
                  "content-length: 5\r\n"
                  "content-type: application/x-www-form-urlencoded\r\n"
                  "hello";

if(BIO_write(bio, write_buf, strlen(write_buf)) <= 0)
{

However, my request is getting rejected with:

HTTP/1.1 505 HTTP Version Not Supported

After Googling I think this could be a generic error response, particularly with un-escaped spaces.

I’m not sure what is the exact problem.

My SSL connection is fine, it works perfectly with a GET request. The problem appears to be in the format of the POST request message.

>Solution :

This is HTTP/1.1. HTTP/2 is a binary protocol. Just change your /2 to /1.1 and you should get unstuck. HTTP/1.1 is not deprecated.

Curl verbose logging doesn’t show the wire protocol, but rather just what it semantically sent.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading