【问题标题】:PHP Curl Force Content-TypePHP 卷曲力内容类型
【发布时间】:2013-07-05 11:22:03
【问题描述】:

尽管我将内容类型设置为 text/plain,但 CURLOP_POSTFIELDS 似乎将其覆盖为 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",

【问题讨论】:

  • 你不能在 CURLOPT_HTTPHEADER 中使用关联数组,你必须像这样添加数组项:array('Content-type: text/plain; charset=utf-8', 'Connection: keep-alive', ... )

标签: php ajax curl http-headers content-type


【解决方案1】:

您必须删除 Content-Type 后的冒号。否则,试试这个:

$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);

【讨论】:

    猜你喜欢
    • 2012-09-08
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多