C++ HTTP 2 POST请求被拒绝

huangapple go评论59阅读模式
英文:

C++ HTTP 2 POST request getting rejected

问题

这是您在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";

但是,您的请求被拒绝,并出现以下错误:

HTTP/1.1 505 HTTP Version Not Supported

根据您的描述,这可能是一个通用错误响应,特别是与未转义的空格有关。问题似乎出现在POST请求消息的格式上。如果您的SSL连接在GET请求中工作正常,那么问题可能在于POST请求的格式。

英文:

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:

> 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.

答案1

得分: 0

这是HTTP/1.1。HTTP/2是一种二进制协议。只需将您的 /2 更改为 /1.1,您就应该解决问题了。HTTP/1.1并没有被废弃。

Curl的详细日志记录不显示传输协议,而只是显示语义上发送的内容。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月6日 03:01:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定