邮递员请求工作,手动执行不。没有错误,只是不起作用

问题描述 投票:0回答:1

当我使用Postman对POST的API(https://pushpad.xyz/docs/rest_api)进行POST请求时,它按预期工作,我在桌面上获得推送通知。但是,当我手动执行它时,它只显示一些破坏的HTML代码,它似乎是Pushpad的仪表板。我没有得到任何错误,我得到状态代码200说好。

我已经尝试过以下方法:

$client = new Client([
            'headers' => [ 'Content-Type' => 'application/json' ],
            ['Authorization' => 'Token token="for the sake of privacy removed in this question"'],
            ['Accept' => 'application/json'],
        ]);

        $response = $client->post('https://pushpad.xyz/api/v1/projects/1234/notifications', [
                'json' => [
                    ['body' => 'testbody' , 'title' => 'testtitle']
                ]
            ]);
        echo '<pre>' . var_export($response->getStatusCode(), true) . '</pre>';
        echo '<pre>' . var_export($response->getBody()->getContents(), true) . '</pre>';
        dd($response->getBody()->getContents());

我得到的状态代码为200,对于内容或正文,我只是得到一个简单的'所以问题是,为什么它在Postman中有效而不是手动。 (使用Laravel 5.5,Guzzle)有关我在邮递员中所做的更多详情以及我的手动代码给我的结果,请参阅图像。 (参数是空的)非常感谢! image

json laravel post postman guzzle
1个回答
0
投票

看看标题的章节大括号。

new Client([
  'headers' => [
    'Content-Type' => 'application/json',
    'Authorization' => 'Token token="for the sake of privacy removed in this question"',
    'Accept' => 'application/json',
  ],
]);
© www.soinside.com 2019 - 2024. All rights reserved.