开发者

libcUrl Bad request. Seem that POST body isn't sent, only header

I use this options:

curl_easy_setopt(curl, CURLOPT_URL, urlUpload);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, body.length());
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());

I'm trying to upload file to Youtube following their manual, header and body of my request is quite the same as in the manual.

I receive Bad request, verbose mode shows the following:

* About to connect() to uploads.gdata.youtube.com port 80 (#0)
*   Trying 74.125.XX.XXX... * connected
* Connected to uploads.gdata.youtube.com (74.125.XX.XXX) port 80 (#0)
> POST /feeds/api/users/default/uploads HTTP/1.1

Accept: */*

Host: uploads.gdata.youtube.com

Authorization: GoogleLogin    auth=D *** c

GData-Version: 2

X-GData-Key: key=A *** Q

Slug: screen.avi

Content-Type: multipart/related; boundary="d31fcjR2"

Content-Length: 910273

Connection: close

Expect: 100-continue



* Done waiting for 100-continue
< HTTP/1.1 400 Bad Request

< Server: Upload Server Built on Aug 29 2011 16:45:26 (1314661526)

< Content-Type: text/plain; charset=utf-8

< Date: Wed, 07 Sep 2011 12:57:51 GMT
开发者_运维技巧
< Pragma: no-cache

< Expires: Fri, 01 Jan 1990 00:00:00 GMT

< Cache-Control: no-cache, no-store, must-revalidate

< Content-Length: 11

< Connection: close

< 

* Closing connection #0

Seems like for some reason body wasn't sent at all, can someone helps me?

UPDATE:

when I disable Expect: header I still got the Bad Request.

* About to connect() to uploads.gdata.youtube.com port 80 (#0)
*   Trying 74.125.XX.XXX... * connected
* Connected to uploads.gdata.youtube.com (74.125.XX.XXX) port 80 (#0)
> POST /feeds/api/users/default/uploads HTTP/1.1

Accept: */*

Host: uploads.gdata.youtube.com

Authorization: GoogleLogin auth=D *** s

GData-Version: 2

X-GData-Key:    key=A *** Q

Slug: screen.avi

Content-Type: multipart/related; boundary="d31fcjR2"

Content-Length: 910273

Connection: close



< HTTP/1.1 400 Bad Request

< Server: Upload Server Built on Aug 29 2011 16:45:26 (1314661526)

< Content-Type: text/plain; charset=utf-8

< Date: Wed, 07 Sep 2011 13:59:38 GMT

< Pragma: no-cache

< Expires: Fri, 01 Jan 1990 00:00:00 GMT

< Cache-Control: no-cache, no-store, must-revalidate

< Content-Length: 11

< Connection: close

< 

* Closing connection #0


My error was because of the mistake in the POST body. SO this cUrl option is the right way to form POST request with header.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜