小编Kyl*_*yle的帖子

cURL'内容长度要求'错误... 3天搜索,没有运气

在你提出问题之前:我已经检查过每个已经有答案的类似问题,并且所提出的解决方案都不起作用.所以我希望有人能够注意到我的代码中的错误.

在向Google提交cURL帖子时,我收到411错误,"POST请求需要内容长度标头"

//Info required to authenticate
$URL = "https://www.google.com/accounts/ClientLogin";
$POST = http_build_query(array(
 'Email' => 'XXXXXXX@gmail.com',
 'Passwd' => 'XXXXXXXXXXXXXXX',
 'source' => 'primary',
 'service' => 'cl'
));

$ch = curl_init( $URL );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $POST);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$response = curl_exec($ch); //returns SID=<sid code>nLSID=<lsid code>nAuth=<auth code> or ERROR=<message>
if ( curl_errno($ch) )
 die( 'Error contacting server' );

//Successful auth results in http code 200
if ( curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200 )
 die( 'Failed …
Run Code Online (Sandbox Code Playgroud)

php curl google-calendar-api

7
推荐指数
2
解决办法
3万
查看次数

标签 统计

curl ×1

google-calendar-api ×1

php ×1