php - 在 POST API 中使用 guzzle 时出现问题如何解决?
问题描述
我的框架是 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"}}"
在此之前,我尝试过邮递员并成功,并且使用的数组的结构是相同的。
解决方案
看起来这个字符串 ( "{"status": "ERROR", "error": {"message": "Something went wrong.", "kind": "APIException"}}"
) 是一个有效的服务器响应。
我的意思是你这边没有错误,你从服务器得到这个响应。服务器应用程序内部出现问题,您收到此消息。
在我看来,您似乎应该意识到这种类型的响应并在您的应用程序中以某种方式处理它们。
推荐阅读
- c# - 我的构建模式是 Release 但作为输出我得到 Debug 文件夹,有什么问题?
- powershell - Powershell - 退出应用程序后继续执行脚本
- java - 如何使我的部分活动保持固定和静态
- javascript - 如何在grapesjs工具栏中添加自定义按钮?
- sql - Power BI 中的 JSONB 查询
- c# - 有人对 C# 中的基本计时器有一个好主意吗?
- mysql - GroupConcat 中缺少空值
- html - 带有标题和注释的 HTML 图
- python - 输入最多 9 位数字(小于 10 亿)。使用 Python,将数字打印为字母
- plot - 如何在原子编辑器中显示 julia Gadfly 图?