我正在使用Pest PHP REST client对http://rolz.org/api/?4d20上的web应用程序进行我认为最基本的API调用。使用Chrome插件REST客户端,我得到了预期的结果,没有错误:
result=45
details= [ 16 +20 +3 +6 ]
code=4d20
illustration=<span class="dc_dice_a">4</span><span class="dc_dice_d">D20</span>
timestamp=1370200094但是,使用Pest PHP REST client时,我的结果前面会出现一条错误消息:
string $rolldice = result=Error: please check your formula (/52)
details=/ [ 9 +16 +20 +7 ]
code=/4d20
illustration=<span class="dc_operator">/</span><span class="dc_dice_a">4</span><span class="dc_dice_d">D20</span>
timestamp=1370200381使用以下代码:
include '../Pest.php';
function callDieRoller($num, $faces){
$result = array();
$curl = curl_init();
$url = 'http://rolz.org/api/?';
$pest = new Pest($url);
$rolldice = $pest->get($num.'d'.$faces);
$results = $rolldice;
return $results;
}为什么在使用Pest进行API调用时会出现错误?
发布于 2013-06-03 04:25:16
这是因为Pest确保了基础api url和被调用的url之间的/,所以你调用的是类似http://rolz.org/api/?/4d20的东西。为了让它正常工作,你必须定义不带问号的基本url,并将其添加到每个调用的前面:
$url = 'http://rolz.org/api/';
$pest = new Pest($url);
$rolldice = $pest->get('?'.$num.'d'.$faces);
$results = $rolldice;https://stackoverflow.com/questions/16886347
复制相似问题