簡體   English   中英

發送帶有curl的請求時出現無效的報頭錯誤

[英]invalid header error on sending a request with curl

這是我的代碼

echo 22;
$url = 'http://www.10bet.com/pagemethods.aspx/GetLeaguesContent';

$fields = array(    
        'BranchID' => urlencode('1') , 
        'LeaguesCollection' => urlencode('10098') , 
                );

$fields_string  = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');



$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type : application/json; charset=utf-8'));
$result = curl_exec($ch);
curl_close($ch);
var_dump( $result );

我不斷

Bad Request - Invalid Header

HTTP Error 400. The request has an invalid header name.

您驚訝地得到了錯誤

Bad Request - Invalid Header

HTTP Error 400. The request has an invalid header name.

因為您使用了無效的標題名稱:)

你用

Content-Type : application/json; charset=utf-8

注意標題名稱中的空格

正確的用法是:

Content-Type: application/json; charset=utf-8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM