我试图像Pythons请求包一样设置POST请求,但是在C ++中。
它应该等同于
url = "https://www.cryptopia.co.nz/Api/GetBalance"
post = '{"Currency": "BTC"}'
headers = {'Content-Type': 'application/json; charset=utf-8', 'Authorization': 'amx xxxxxxxxxxxxxxxxx:V/xxxxxxxxxxx/LuR2fRTWzxxxxxxxxxmeNkY=:111111111111'}
rep = requests.post(url, data=post, header = headers)
然后我尝试使用JSON library和cURL wrapper在C ++中复制此内容。 documentation对我来说并不是那么清楚。
auto header = json;
header["Content-Type"]="application/json; charset=utf-8";
header["Authorization"]="amx xxxxxxxx:V/xxxxxxx/xxxxxx=:11111111";
auto pair = json;
pair["Curency"] = "BTC";
response = cpr::Post(cpr::Url{"https://www.cryptopia.co.nz/Api/GetBalance"},
cpr::Payload{pair},
cpr::Header{header});
它会引发大量错误。我设法通过将它们放在一起进行编译:
response = cpr::Post(cpr::Url{"https://www.cryptopia.co.nz/Api/GetBalance"},
cpr::Payload{{"Currency","BTC"}},
cpr::Header{{"Content-Type", "application/json; charset=utf-8"},{"Authorization", "amx xxxxxxxxx:V/xxxxxxxxxxxx/xxxxxxxx=:1111111111"}});
然后它会抛出以下错误:libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: parse error - unexpected '?' (<parse error>)
Abort trap: 6
请问任何想法?