简体   繁体   中英

PHP Curl Force Content-Type

Even though I set the content type to text/plain, CURLOP_POSTFIELDS appears to be overwriting it to x-www-form-urlencoded

curl_setopt($ch, CURLOPT_POSTFIELDS, 'username etc..');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "type" => "POST",
    "Accept" => "*/*",
    "Content-Type:" => "text/plain; charset=utf-8",
    "X-AjaxPro-Method" => "Authenticate2",
    "Accept-Language" => "en-us,en;q=0.5",
    "Accept-Encoding" => "gzip, deflate",
    "Connection" => "keep-alive",

You'll have to remove the colon after Content-Type. Otherwise, try this:

$headers = array(
    'type: POST',
    'Accept: */*',
    'Content-type: text/plain; charset=utf-8',
    'X-AjaxPro-Method: Authenticate2',
    'Accept-Language: en-us,en;q=0.5',
    'Accept-Encoding: gzip, deflate',
    'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM