libcUrl 错误的请求。似乎 POST 正文未发送,仅发送标题

发布于 2024-12-03 03:49:59 字数 2733 浏览 1 评论 0原文

我使用此选项:

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());

我尝试按照 他们的手册将文件上传到 Youtube ,我的请求的 header 和 body 与手册中的完全相同。

我收到错误请求,详细模式显示以下内容:

* 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

似乎由于某种原因根本没有发送正文,有人可以帮助我吗?

更新:

当我禁用 Expect: 标头时,我仍然收到错误请求。

* 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云仙小弟 2024-12-10 03:49:59

我的错误是由于 POST 正文中的错误造成的。所以这个 cUrl 选项是使用 header 形成 POST 请求的正确方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文