我已经开始使用 cURL 库,在工作之前我会编译库。我发送请求并遇到一些问题。我用于处理 cURL 的 C++ 代码:
CURL *curl=NULL;
CURLcode res;
struct curl_slist *headers=NULL; // init to NULL is important
curl_slist_append(headers, "POST /oauth/authorize HTTP/1.1");
curl_slist_append(headers, "Host: sp-money.yandex.ru");
curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
curl_slist_append(headers, "charset: UTF-8");
curl_slist_append(headers, "Content-Length: 12345");
curl = curl_easy_init();
if(!curl)
return 0;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, "sp-money.yandex.ru");
curl_easy_setopt(curl, CURLOPT_PROXY, "127.0.0.1:8888");
if( curl_easy_perform(curl)!=CURLE_OK)
return 1;
我使用代理 fiddler2 来检查发送到服务器的数据。当我检查发送的数据时 我得到结果:
POST HTTP://sp-money.yandex.ru/ HTTP/1.1
Host: sp-money.yandex.ru
Accept: */*
Connection: Keep-Alive
Content-Length: 151
Content-Type: application/x-www-form-urlencoded
我还使用 Wiresharck 检查此数据,结果相同。
你知道为什么 cURL 在第一行写:
POST HTTP://sp-money.yandex.ru/ HTTP/1.1
我发
POST /oauth/authorize HTTP/1.1
我在工作中使用 VS 2010,而且我没有使用框架
最佳答案
POST/oauth/authorize HTTP/1.1
不是 header ,它是带有 URL 和版本的 HTTP 动词 (POST)。
我想你需要把它放在别处(现在再看看文档)
关于c++ - cURL 请求已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8239737/