【问题标题】:Unirest post method doesn't work?Unirest post方法不起作用?
【发布时间】:2015-03-19 19:15:37
【问题描述】:

我有一个非常短的代码 sn-p 直接取自 mashape:

我已经正确地包含了路径,如下:

require_once 'unirest-php-master/src/Unirest.php';

以及发送POST请求的代码sn-p:

$response = Unirest::post("",
      array(
        "X-Mashape-Key" => "",
        "Content-Type" => "application/x-www-form-urlencoded",
        "Accept" => "application/json"
      ),
      array(
        "selector" => "FACE, EYES, FULL",
        "url" => "http://api.animetrics.com/img/test/sc.jpg"
      )
    );

(我故意将 post("url") 和 X-Mashape-Key 留空,因为它们是私钥。)

我不确定为什么这不起作用 - 我尝试通过添加方法在相应文件的 post 方法中回显虚拟文本:

public static function echo($a) {
    echo $a;
}

在 Request.php 中,但是当我尝试使用 Unirest::echo("abc"); 调用此方法时,它也不起作用。这种语法有问题还是我没有看到其他问题?

我 100% 确定我的文件路径是正确的。我觉得我错过了一些我没有看到的明显事实 - 非常感谢您的帮助。

谢谢!

【问题讨论】:

    标签: php post unirest


    【解决方案1】:

    Unirest 2.0 的发布有一些重大变化,主要是方法和类签名发生了变化。不幸的是,Mashape 示例 sn-ps 尚未更新。

    例如:您应该调用Unirest\Request::post,而不是调用Unirest::post,有关详细信息,请参阅unirest documentation

    我们将很快更新 Mashape 示例以反映这一变化。

    我是 unirest-php 的作者,在 Mashape 工作。

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 1970-01-01
      • 2018-08-23
      • 2012-05-31
      • 2019-01-07
      • 2018-01-28
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多