检索从Laravel用Guzzle(6.3)发送的POST数据

时间:2019-06-07 23:44:22

标签: php laravel guzzle

我正在将laravel应用中的一些数据发布到本地服务器上的另一个普通PHP页面。 Guzzle返回的状态代码表示成功,但是我无法访问它。我该怎么办?

我尝试使用Post方法检索值,但没有运气

枪口功能

$client = new Client();
    $response = $client->request('POST', 'http://localhost/testApp/guzTest.php',
        [
            'form_params' => [
                'amnt' =>  75
            ],
            'allow_redirects' => true
        ]);
    echo $response->getStatusCode();

页面接收POST数据:

<?php
    if (!empty($_POST['amnt'])) {
        echo $_POST['amnt'];
    }else
        echo 'not found';   
?>

我希望能够通过邮寄方式访问邮寄的金额,但不会产生任何收益。

1 个答案:

答案 0 :(得分:2)

尝试类似的东西。

 $client = new Client();
    $response = $client->request('POST', 'http://localhost/testApp/guzTest.php',
        [
            'form_params' => [
                'amnt' =>  75
            ],
            'allow_redirects' => true
        ]);

$contents = $response->getBody()->getContents();
$contents = json_decode($contents,true);

return ($contents);

在接收POST数据的页面上: 响应应该是这样

  return response()->json([
            'status' => 'SUCCESS',
            'code' => '200',
        ], 200);