簡體   English   中英

PHP Guzzle POST請求返回空值

[英]PHP Guzzle POST Request Returning Null

我為此絞盡腦汁-郵遞員的要求很好,但是我無法使用Guzzle進入身體。

$client = new \GuzzleHttp\Client();

        $res = $client->request('POST',  'https://apitest.authorize.net/xml/v1/request.api', [
            'headers' => [
                'Content-Type' => 'application/json',
            ],
            'body' => json_encode([
                'createTransactionRequest' => [
                    'merchantAuthentication' => [
                        'name' => '88VuW****',
                        'transactionKey' => '2xyW8q65VZ*****'
                    ],
                    'transactionRequest' => [
                        'transactionType' => 'authCaptureTransaction',
                        'amount' => "5.00",
                        'payment' => [
                            'opaqueData' => [
                                'dataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT',
                                'dataValue' => $_POST['dataValue']
                            ]
                        ]
                    ]
                ]
            ])
        ]);

        dd(json_decode($res->getBody()));

上面的返回null-沒有錯誤,只是null。 以下是Postman中的相同請求,成功完成了一個屍體。

在此處輸入圖片說明

任何想法將不勝感激,謝謝!

您應該使用$res->getBody()->getContents()

並在發生任何錯誤的情況下json_decode()返回null 您必須使用json_last_error()單獨(不幸地)對其進行檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM