C++ cURL请求已更改

C++ cURL请求已更改,c++,curl,http-headers,C++,Curl,Http Headers,在编译库之前,我已经开始使用cURL库。我发送请求时遇到了一些问题。我用CURL工作的C++代码:< /P> 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-

在编译库之前,我已经开始使用cURL库。我发送请求时遇到了一些问题。我用CURL工作的C++代码:< /P>
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

我在工作中使用了VS2010,也没有使用framework

POST/oauth/authorize HTTP/1.1
不是标题,而是带有URL和版本的HTTP动词(POST)


我想你需要把它放在别处(现在再看一下文档)

POST
行不属于标题,它应该设置为
CURLOPT\u URL
CURLOPT\u POST
,以及类似协议的内容。实际上,
主机:
头也是如此,它是从URL推断出来的。

我不是libcurl大师,不会说我有经验,但我碰巧使用了一点:)