【问题标题】:Unirest POST request won't run in PHPUnirest POST 请求不会在 PHP 中运行
【发布时间】:2015-03-19 23:22:07
【问题描述】:

我有一段代码几乎是准系统,但由于某种原因,它只是拒绝运行:

<?php
require_once "unirest/src/Unirest.php";

$photo_url = "http://api.animetrics.com/img/test/sc.jpg";
// These code snippets use an open-source library.
$response = Unirest::post("<--URL-->",
  array(
    "X-Mashape-Key" => "<--API 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"
  )
);
echo $response;
?>

此代码块直接取自 mashape 网站,我只是下载了 Unirest 文件。我也确信我的路径是正确的。

我进行了一些调查,并尝试在 Unirest 文件中添加一个静态类函数以打印出一些内容,不出所料,它不起作用。

这是我添加的代码块:

<?php

namespace Unirest;

echo "in file";

$file = new File(); 

$file->printa("abc");

class File
{

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

在同一个文件中,$file-&gt;printa("abc"); 运行良好,但是当从不同的文件中调用时,File::printa("abc");Unirest::printa("abc");File\Unirest::printa("abc"); 只是拒绝运行。

我不确定,但我对命名空间有误解吗?我会认为Unirest::printa("abc"); 是访问静态类函数的正确方法吗?

如果有任何关于此的建议,我将不胜感激,谢谢。

【问题讨论】:

    标签: php post namespaces unirest


    【解决方案1】:

    自 Unirest 2.0 发布以来,方法和类签名发生了变化。不幸的是,Mashape 示例 sn-ps 尚未更新。

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-11-06
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 2020-12-13
      相关资源
      最近更新 更多