0

我正在做我认为是使用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 客户端,我的结果前面会出现一条错误消息:

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 调用时会出错?

4

1 回答 1

1

这是因为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;
于 2013-06-02T20:25:15.847 回答