0

Google は 411 エラーを表示しましたが、既に Content-Length をヘッダーに入れています。このエラーを修正するにはどうすればよいですか?

$authToken = getAuthorizationToken();
$xml_data = '<?XML version="1.0"?>
    <Batch>
   <Remove>    
  <Promotions>      
   <Promotion id="d5111e0a"/>
  </Promotions>
  </Remove>
</Batch>';
$length = strlen($xml_data);
$ch = curl_init("http://www.google.com/cse/api/default/promotions/pe0dnd27zuc");
$header = array();
$header[] = 'Authorization: GoogleLogin auth=' . $authToken;
$header[] = 'Content-Type: text/xml';
$header[] = 'Content-Length: ' . $length;
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
4

2 に答える 2

2

ヘッダー配列からContent-Length部分を削除します。cURL によって自動的に追加されます。だからあなたはそれを送る必要はありません。削除する:


//remove following
$header[] = 'Content-Length: ' . $length;

それが役に立てば幸い

于 2012-02-28T04:17:56.197 に答える
0

これを試して:

    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch,CURLOPT_POST, $length); //count of your posted array
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
    $result = curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

投稿されたフィールドの長さ/数がありません。

于 2012-02-28T08:35:38.960 に答える