PHP Guzzle获取请求格式

时间:2019-03-13 17:08:29

标签: json guzzle

我正在尝试使用Guzzle获取JSON feed,这是我第一次。

我得到的身体样本是:

{
    "auth": {
        "key": "samplekeyhere",
        "secret": "samplesecrethere"
    }
}

这是我的代码:

    $res = $client->request(
                'GET',
                'https://urltofeed',
                [
                    "verify" => false, // JUST FOR TESTING NOW
                    "headers" => [
                        "Content-Type" => "application/json;charset=UTF-8"
                    ],
                    "json" => [
                        "key" => "samplekeyhere",
                        "secret" => "samplesecrethere"
                    ]
                ]
    );
    $body = $res->getBody();

$jsonResponse = json_decode($body);
var_dump($jsonResponse);

输出为:

status code is200object(stdClass)#2455 (2) { ["success"]=> bool(false) ["msg"]=> string(7) "Error 1" }

我的语法是否有问题,还是应该要求新的密钥和秘密?

1 个答案:

答案 0 :(得分:0)

react-native run-ios --simulator 'iPhone 6s'

因为主体是$jsonResponse = json_decode($body->getContents()); 的实例,而不是简单的字符串。