0

我正在尝试向此 URL 发出发布请求:

http://clan.z8games.com/clanServices.asmx/getPlayerPublicInfo

使用这个 JSON 字符串

{"usn":12434525}

获得与此类似的输出;

 {"d":"{\"usn\":12434525,\"nick\":\"Guiness\",\"lev\":39,\"playCnt\":3734,\"winCnt\":3210,\"loseCnt\":239,\"enemyKillCnt\":129734,\"deathCnt\":5140,\"exp\":1072522,\"headshotKillCnt\":120339,\"friendKillCnt\":5,\"escapeCnt\":45,\"regDate\":\"2011\",\"lastPlayDate\":\"2012-08-12\",\"guildid\":217089,\"clanName\":\"Guiness™\",\"memberType\":null,\"gcClanID\":55000,\"hs5p\":202,\"fk1p\":0,\"k10p\":211,\"d20p\":2,\"esc4p\":0,\"sv3p\":676,\"matchLosses\":98,\"matchWins\":1894}"}

因为我为游戏帐户(如统计数据)制作了一个数据抓取器,并且每个页面都根据帐户 ID 而有所不同。

我试过这个:

<?php 
$usn=$_GET["accountUSN"]; 
$url='http://clan.z8games.com/clanServices.asmx/getPlayerPublicInfo';

$options = array(
    'http' => array(
        'method' => "POST",
        'content' => http_build_query(
            array(
                'usn'=>$usn
             )
        )
    )
);

$context = stream_context_create($options);
$result =  file_get_contents($url,NULL,$context);
var_dump($result);
?>

有人建议这样做,但它总是返回

bool(false)

我只是想知道如何正确地做到这一点,如果它让你感觉更好,我真的不想要任何完整的代码。另外,我试图避免 cURL,我想要一个原生选项。

此外,有人试图在这里帮助我: https ://stackoverflow.com/questions/11920064/php-simple-html-dom-parser-not-giving-me-text-for-a-td 但我不小心删除了发布,成为新用户。我怎样才能取消删除这个?

编辑:

<?php

$usn=$_GET['accountUSN'];
$url='http://clan.z8games.com/clanServices.asmx/getPlayerPublicInfo';

$options=array('http'=>array('method'=>'POST','content'=>'content' => '{\'usn\':$usn}'));

$context=stream_context_create($options);
$result=file_get_contents($url,NULL,$context);
var_dump($result);
?>

服务器错误。

4

2 回答 2

0

我使用它的方式是打开文件,然后从文件指针中获取流内容。

$context = stream_context_create($options); 
$fp = fopen($url, 'rb', false, $context);
if (!$fp) {
   die('Failed to open stream');
}
$result = stream_get_contents($fp);
var_dump($result);
于 2012-08-14T01:50:04.457 回答
0

可能您可以使用 firebug,请参阅 Net 选项卡,比较您以编程方式发送的内容和浏览器发送的内容。确保您发送了它想要的东西。

于 2012-08-14T02:51:00.670 回答