如何通过大量服务获取状态代码?

时间:2019-03-11 11:04:13

标签: laravel guzzle

我正在尝试使用Guzzle Services,但不知道如何获取回购的状态码。这是我的代码:

services.php

<?php

return [
    'baseUrl'    => '.....', // base url
    'operations' => [
        'setOrder' => [
            'httpMethod'    => 'POST',
            'uri'           => 'Customer/SetCustomerOrder',
            'responseModel' => 'GetResponse',
            'parameters'    => [
                'order' => [
                    'type'     => 'object',
                    'location' => 'uri',
                    'required' => true
                ]
            ]
        ],
    ],
    'models'     => [
        'GetResponse' => [
            'type'                 => 'object',
            'additionalProperties' => [
                'location' => 'json'
            ],
        ],
    ]
];

Client.php

<?php

namespace App\Libraries;

use GuzzleHttp\Command\Guzzle\Description;
use GuzzleHttp\Command\Guzzle\GuzzleClient;

class Client extends GuzzleClient
{
    public function __construct($config = [])
    {
        $client = new \GuzzleHttp\Client([
            'auth'    => [
                'Test', 'test'
            ],
            'headers' => [
                'Accept' => 'application/json',
                'Content-type' => 'application/json'
            ]
        ]);


        $services = include __DIR__ . '/services.php';
        $description = new Description($services);

        parent::__construct($client, $description);
    }
}

如果我想在控制器中获取状态码,则会收到错误消息:调用未定义的方法GuzzleHttp \ Command \ Result :: getStatusCode()

  $client = new \App\Libraries\Client();
    $data = ["OrderHeader" => [
        "CustomerCode"        => "123",
        "CustomerName"        => "name",
        "DeliveryAddress"     => "address"
    ]
    ];
    $response = $client->setOrder(['order' => $data]);

    dd($response->getStatucCode());

0 个答案:

没有答案