【问题标题】:How to solved something went wrong when using guzzle in POST API?在 POST API 中使用 guzzle 时出现问题如何解决?
【发布时间】:2019-04-29 14:59:50
【问题描述】:

我的框架是 codeigniter,我制作这样的库:

function checkOut($url, $params){
        $client = new GuzzleHttp\Client([
            'headers' => [ 'Content-Type' => 'application/json' ,'Accept' => 'application/json; charset=utf-8'],
            'verify' => false,
            'cookies' => true
        ]);

        $response = $client->request('POST', $url, [
            'json' => $params
        ]);

        return $response->getBody->getContents();
    }

我在我的控制器中这样调用这些库:

$dataArray is some array was i make,

$response_checkout = $this->corekredivo->checkOut($url, $dataArray)

在视图中我只是解析为这样的视图:

$data = array(
            '_respon' => $response_checkout
        );]

但是,当var_dump(); 在视图中时,结果是:

string(90) "{"status": "ERROR", "error": {"message": "发生了什么事 错误。", "kind": "APIException"}}"

在此之前我在邮递员中尝试过并且成功并且使用的数组的结构是相同的。

【问题讨论】:

  • 请参考此link 了解如何接受答案。要将答案标记为已接受,请单击答案旁边的复选标记以将其从灰色切换为已填充。

标签: php json guzzle


【解决方案1】:

看起来这个字符串 ("{"status": "ERROR", "error": {"message": "Something went wrong.", "kind": "APIException"}}") 是一个有效的服务器响应。

我的意思是你这边没有错误,你从服务器得到这个响应。服务器应用程序内部出现问题,您收到此消息。

在我看来,您应该注意这种类型的响应并在您的应用中以某种方式处理它们。

【讨论】:

    猜你喜欢
    • 2017-08-19
    • 2019-08-16
    • 1970-01-01
    • 2010-09-11
    • 2019-03-15
    • 2015-07-18
    • 2021-08-15
    • 2020-06-15
    • 2019-10-29
    相关资源
    最近更新 更多