【发布时间】:2020-11-02 10:00:17
【问题描述】:
我有 cURL 命令:
curl "https://pelevin.gpt.dobro.ai/generate/" --data-binary '{"prompt" : "text" , "length" : 40}
我想在 C++ 中做同样的事情。
我试过了:
string params = "prompt=text&length=40";
string buffer;
CURL* curl;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://pelevin.gpt.dobro.ai/generate/");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, params.size());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, params.c_str());
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
收到这样的消息:
{"detail":[{"loc":["body",0],"msg":"Expecting value: line 1 column 1 (char 0)","type":"value_error.jsondecode","ctx":{"msg":"Expecting value","doc":"prompt=text&length=40","pos":0,"lineno":1,"colno":1}}]}
如何正确提出请求?
【问题讨论】: