【问题标题】:How to get this node ID by cURL in PHP?如何在 PHP 中通过 cURL 获取此节点 ID?
【发布时间】:2018-09-06 00:11:58
【问题描述】:

我在 unkownNodeId 上保存了一些文件,只知道在 0 到 5 范围内 http://example.com/api/node/fileId/unkownNodeId

当我发送请求获取 fileId 时,例如是 2233 http://example.com/api/node/2233/unkownNodeId

我总是必须像这样http://example.com/api/node/2233/0 1 2 3 4 5 一个一个地尝试 当我得到错误的 unkownNodeId 时,服务器只响应 json 数组 {"status":false} 无论如何通过curl发送请求,然后在正确的nodeId上停止?

【问题讨论】:

  • 是的,可以通过 curl 完成。你尝试了一些 curl 电话吗?你可以在 for 循环中使用 Curl 来实现它

标签: php json api curl


【解决方案1】:

不要认为 curl 自己可以做到这一点,而是使用脚本语言与 curl 结合使用,这是微不足道的。例如使用 php-cli:

php -r '$ch=curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
for($i=0;$i<6;++$i){
    curl_setopt($ch,CURLOPT_URL,"http://example.com/api/node/2233/".$i);
    $ret=curl_exec($ch);
    if($ret!=="{\"status\":false}"){
        echo "correct node id: $i";
        return;
    }
}'

输出:correct node id: 0

【讨论】:

    猜你喜欢
    • 2012-05-10
    • 2013-11-16
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 2019-10-12
    • 2014-10-30
    • 2014-11-29
    相关资源
    最近更新 更多