【问题标题】:Curl PHP Error, how to fix?卷曲PHP错误,如何解决?
【发布时间】:2017-05-31 11:36:18
【问题描述】:

我正在执行以下脚本:(Mojang Api)

curl_setopt($ch, CURLOPT_URL,            "https://authserver.mojang.com/authenticate" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST,           1 );
$headers = array(
    'Accept: application/json','Content-Type=application/json'

);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POSTFIELDS,     '{
    "agent": {                              
        "name": "Minecraft",                
        "version": 1                        

    },
    "username": "idk",      

    "password": "something",
    "requestUser": true                     
}' ); 
curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: text/plain')); 

$result=curl_exec ($ch);
echo $result;

它给出了这个答案:

{"error":"Unsupported Media Type","errorMessage":"The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method"}

如何修复不支持的媒体类型的错误?

【问题讨论】:

  • 我用邮递员试了一下,邮递员正在工作。

标签: php api curl


【解决方案1】:

我是一头牛。

这行代码

curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: text/plain')); 

告诉它的纯文本

但它必须是这样的:

curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: application/json')); 

【讨论】:

    猜你喜欢
    • 2017-05-21
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 2020-06-25
    相关资源
    最近更新 更多