PHP with cURL for POST


PHP with cURL for POST

我几乎没有使用 cURL 获取内容结果的功能;当我在没有开机自检的情况下尝试时,一切正常,但启用了开机自检,结果为空。

此代码不起作用:

function getAPI($url){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST, true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,'shard=Apex');     
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
    $result = curl_exec($ch);
    return $result; 
    curl_close($ch);
}   

此代码有效,但请求不像 POST 那样传递:

function getAPI($url){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    //curl_setopt($ch,CURLOPT_POST, true);
    //curl_setopt($ch,CURLOPT_POSTFIELDS,'shard=Apex');   
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
    $result = curl_exec($ch);
    return $result; 
    curl_close($ch);
}   

我用以下命令调用这个函数:

echo getAPI('http://world.needforspeed.com/SpeedAPI/ws/cmsbridge/news/rss/fr_FR');

您也可以尝试使用此网址

http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/levelkro/profile

此 URL 仅在 shard=Apex 时才有效(CHHICANE 服务器的默认分片=CHICANE,但我的 profil 仅在 Apex Server 上可用)

根据 SpeedAPI 手册(一个简单的谷歌搜索),给定的 URL 似乎不接受"分片"POST-参数...

获取新闻 RSS 提要的 SpeedAPI 手册

但是,您可以使用 GET 请求,并根据手册在适用的情况下使用分片参数。

例如:http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/DRIVER_NAME/profile?shard=APEX(确保以大写字母输入分片参数)

您是否尝试过将参数作为数组传递,如下所示:

curl_setopt($ch,CURLOPT_POSTFIELDS,array('shard' => 'Apex'));