2011-11-23 71 views
0

在编译库之前,我已经开始使用cURL库。我发送请求,并有一些问题。我使用cURL工作的代码:cURL请求已更改

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; 

我已经使用proxy,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,导致相同的检查这个数据。

你知道为什么在第一线卷曲写道:

POST HTTP://sp-money.yandex.ru/ HTTP/1.1 

我送

POST /oauth/authorize HTTP/1.1 

我使用VS 2010的工作,也是我不使用框架

回答

1

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

我想你需要把其他地方(将着眼于文档的第二noww)

1

POST线不属于头,它应该CURLOPT_URLCURLOPT_POST进行设置,类似的东西了协议。实际上,Host:标题也是如此,它是从URL中推断出来的。

+0

+1我的发现也很遗憾没有经历过卷曲 – sehe

+0

我不是一个libcurl大师,不会说我有经验,但是我碰巧用它了一下:) –