这是代码(从现有应用程序中提取):
CURL *curl = curl_easy_init();
_ASSERTE(curl);
string url = "http://127.0.0.1:8000/";
char *data = "mode=test";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_URL, url);
CURLcode res = curl_easy_perform(curl);
bool success = (res == CURLE_OK);
curl_easy_cleanup(curl);
Run Code Online (Sandbox Code Playgroud)
res的值为CURLE_URL_MALFORMAT。这个URL与curl不兼容吗?
Nic*_*ton 10
啊,简单的错误,我需要传递char *到curl_easy_setopt而不是string。为了解决这个问题,我只是.c_str()这样使用:
CURL *curl = curl_easy_init();
_ASSERTE(curl);
string url = "http://127.0.0.1:8000/";
char *data = "mode=test";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
CURLcode res = curl_easy_perform(curl);
bool success = (res == CURLE_OK);
curl_easy_cleanup(curl);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13681 次 |
| 最近记录: |