我使用这个选项:
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());
我正在尝试在their manual之后将文件上传到Youtube,我的请求的标题和正文与手册中的完全相同。
我收到错误请求,详细模式显示以下内容:
* 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
似乎因为某种原因身体根本没被发送,有人可以帮助我吗?
更新:
当我禁用期望:标题时,我仍然收到错误请求。
* 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
答案 0 :(得分:1)
我的错误是因为POST正文中的错误。所以这个cUrl选项是用标题形成POST请求的正确方法。