为什么我不能在PHP中使用curl请求设置标头?

时间:2015-02-05 13:11:25

标签: php post curl

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'somesite.com');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Accept: application/json',
    'Content-Length: ' . strlen($body)
));

返回响应 HTTP / 1.1 401 Unauthorized Content-Type:text / html;

但是我将内容类型设置为application / json,如上所示。为什么呢?

0 个答案:

没有答案