簡體   English   中英

使用 libcurl C++ 發送帖子請求 問題:s

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM