Set HTTP Request “Content-Type”

后端 未结 2 2002
傲寒
傲寒 2021-01-12 01:58

How do you set the content type of an HTTP Request?

I\'ve tried this:

$headers[\'Accept\'] = \'application/xml\';
$headers[\'Content-Type\'] = \'appl         


        
2条回答
  •  不要未来只要你来
    2021-01-12 02:23

    I believe the headers must be a plain array whose elements are full key:value headers, not an associative array:

    $headers = array();
    $headers[] = 'Accept: application/xml';
    $headers[] = 'Content-Type: application/xml';
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    

    This is specified in the curl_setopt() documentation.

提交回复
热议问题