![](/img/trans.png)
[英]C++ - how to send a HTTP post request using Curlpp or libcurl
[英]Send a post request with libcurl C++ question :s
我用 libcurl 成功完成了我的 GET 請求,沒問題!
但是,當我嘗試發送發布請求時,我不確定將 json 數據放在哪里,我想被發送過去..
我的代碼看起來像這樣,我想知道是否有一種方法可以按原樣發送數據:
CURL* curlpost;
curl_global_init(CURL_GLOBAL_ALL);
curlpost = curl_easy_init();
if (curlpost) {
curl_easy_setopt(curlpost, CURLOPT_URL, "https://127.0.0.1:50006/lol-lobby/v2/lobby");
// post data:
curl_easy_setopt(curlpost, CURLOPT_POSTFIELDS, "{
"customGameLobby": {
"configuration": {
"gameMode": "CLASSIC", "gameMutator" : "", "gameServerRegion" : "",
"mapId" : 11,
"mutators" : {"id": 1}, "spectatorPolicy" : "AllAllowed", "teamSize" : 5
}
},
"queueId": 830,
"isCustom" : false
}")
這不起作用,是我想發送到服務器的原始 JSON 數據。
我如何將數據發送到服務器是我的問題?
JSON 待發送數據:
{
"customGameLobby": {
"configuration": {
"gameMode": "CLASSIC",
"gameMutator": "",
"gameServerRegion": "",
"mapId": 11,
"mutators": {"id": 1},
"spectatorPolicy": "AllAllowed",
"teamSize": 5
}
},
"queueId": 830,
"isCustom": false
}
使用curl_easy_escape
對 URL 編碼給定的 C 字符串:
char* encoded = curl_easy_escape(curlpost, "{ your post data }", 0);
// use "encoded"
// free the memory
curl_free(encoded);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.