错误411(长度必需)在post请求与头,但头有Content-Length。 libCurl [英] Error 411 (Length Required) in post request with header, but header has Content-Length. libCurl

查看:4611
本文介绍了错误411(长度必需)在post请求与头,但头有Content-Length。 libCurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个选项:

curl_easy_setopt(curl, CURLOPT_URL, urlUpload); 
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);

它必须是带有标题的请求后。在标题变量中有长度

It must be post request with header. And in header variable there is length

***
char sizeStr[50];
sprintf(sizeStr, "Content-Length: %d", body.length());

*** 

header = curl_slist_append(header, sizeStr);

***

我要做的是上传视频到YouTube,我使用他们的手工

What I'm trying to do is to upload video to YouTube, I'm using their manual

我收到这样的错误。

<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<title>Error 411 (Length Required)!!1</title>
<style>
  *many symbols here* 
</style>
<a href=//www.google.com/ id=g><img src=//www.google.com/images/logo_sm.gif alt=Google></a>
<p><b>411.</b> <ins>Thatв€™s an error.</ins>
<p>POST requests require a <code>Content-length</code> header. <ins>Thatв€™s all we know.</ins>

也许我必须使用其他CURLoptions吗?

Maybe I must use some other CURLoptions?

UPDATE:
当我设置

UPDATE: when I set

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

我也收到

* 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=DQAAAIkAAACTK9tZPCTY1XQvXGkg4qkaIuZ1QO-Bh6-    ZyzOHuigFNC_gR4Piep4NljAjdOP4s-k7vqj-j4LdckXM9jxzlElgtaxr-    CShI1vIWkjm5ZtFsj3a9v1YqFmjIkEi3NCP2ON18D9jmXSIarPqprWiOK0n3oxznCBhm4osXwJ1yRstVVM5bG5mOlC331eMCrOKp3E


GData-Version: 2

X-GData-Key:     key=AI39si59VMkm6DATDmfG_Df6D23jfto3xRVfbAEMrFBv035pdRZ5AYMPsRXbGLCRXXnK5jz6KCSWSkuXOTrlDIIKWy7Le9fkQQ

Slug: screen.avi

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

Content-length: 910273

Connection: close


* HTTP 1.0, assume close after body
< HTTP/1.0 411 Length Required

< Content-Type: text/html; charset=UTF-8

< Content-Length: 11791

< Date: Fri, 02 Sep 2011 16:09:58 GMT

< Server: GFE/2.0

< 

* Closing connection #0


推荐答案

p>这个错误是因为在我从YouTube收到的身份验证字符串结束了新的线符号,我擦除它,这个错误消失了。

This error was because in the authentication string that I receive from YouTube was in the end the new line symbol, I erase it and this error disappeared.

这篇关于错误411(长度必需)在post请求与头,但头有Content-Length。 libCurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆