Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 试图创建一个c++;将带有curl的请求放在某个主体上_C++_Json_Curl_Httprequest_Put - Fatal编程技术网

C++ 试图创建一个c++;将带有curl的请求放在某个主体上

C++ 试图创建一个c++;将带有curl的请求放在某个主体上,c++,json,curl,httprequest,put,C++,Json,Curl,Httprequest,Put,我试图重新创建的是这个卷曲请求 curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic securePasswordHash' -d '{"IconID": 54}' 'https://127.0.0.1:1233/api/v1/current/icon' 这个命令确实有效 我试图把它翻译成C++代码。到目前为

我试图重新创建的是这个卷曲请求

curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic securePasswordHash' -d '{"IconID": 54}' 'https://127.0.0.1:1233/api/v1/current/icon'
这个命令确实有效

我试图把它翻译成C++代码。到目前为止,我的代码如下所示:

{"errorCode":"BAD_REQUEST","httpStatus":400,"message":"Unknown argument '{\"IconID\" : 54}' for 'Icon'."}* Connection #0 to host 127.0.0.1 left intact
std::string wHeader=(“授权:基本”+wLCUEncoded);
std::string strJson=“{\'IconID\”:54}”;
卷曲*卷曲;
卷曲编码;
curl\u global\u init(curl\u global\u默认值);
curl=curl_easy_init();
headerlist=curl\u slist\u append(headerlist,“Accept:application/json”);
headerlist=curl\u slist\u append(headerlist,wHeader.c_str());
if(curl){
curl_easy_setopt(curl,CURLOPT_URL,wUrl.c_str());
curl_easy_setopt(curl,CURLOPT_头,true);
卷曲度(卷曲度,卷曲度(1L));
curl\u easy\u setopt(curl,CURLOPT\u SSL\u VERIFYPEER,0);
curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headerlist);
curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,“PUT”);
curl_easy_setopt(curl,CURLOPT_COPYPOSTFIELDS,strJson);
res=旋度(curl)\u容易执行(curl);
旋度\轻松\清洁(旋度);
}
结果如下所示:

{"errorCode":"BAD_REQUEST","httpStatus":400,"message":"Unknown argument '{\"IconID\" : 54}' for 'Icon'."}* Connection #0 to host 127.0.0.1 left intact
我该怎么做有什么建议吗?我试图将strJson
strJson
转换为实际的json对象,但出现了一个奇怪的字符串错误:

{"errorCode":"BAD_REQUEST","httpStatus":400,"message":"Unknown argument '\u0002╠╠╠╠╠╠╠\u0010^J\u000Fe\u0001' for 'Icon'."}* Connection #0 to host 127.0.0.1 left intact

我的问题的解决方案是包含标题

headerlist = curl_slist_append(headerlist, "Accept: application/json");
headerlist = curl_slist_append(headerlist, "Content-Type: application/json");
headerlist = curl_slist_append(headerlist, "charset: utf-8");

查看服务器日志,这两个请求可能在某些方面有所不同。遗憾的是,我无法访问这些日志,我可能会将其发送到我自己的web服务器并查看其外观,感谢您的建议。
curl\u easy\u setopt(curl,CURLOPT\u COPYPOSTFIELDS,strJson)可能是罪魁祸首。将
std::string
按值传递给此函数可能不起作用。添加一个
.c_str()
。另外,考虑找到一个合适的C++库或库包装器。嘿,谢谢你的回复,什么是合适的包装或库?我不知道。我只在命令行上使用卷曲,而不是从C++中使用PHP。在网上找东西应该不会太复杂(),但我会把挑选一个好东西的任务留给你