首页 > 解决方案 > PHP Guzzle 调用未定义的方法

问题描述

我正在尝试使用这个 github 存储库 https://github.com/otaviobarreto/dlocal-php但我在 Guzzle 上遇到错误

调用未定义的方法 GuzzleHttp\Client::request()

这是php代码:

<?php

namespace Fripixel\DLocal\Core;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

class Request
{
    public $client = null;

    public $baseURI = null;

    public $timeout = 2.0;

    public function __construct($config, $debug = false)
    {
        $this->client = new Client([
            'base_uri' => $config->base_uri,
            'timeout'  => $this->timeout,
            'debug'    => $debug,
        ]);

        $this->baseURI = $config->base_uri;
    }

    public function get($url, $headers)
    {
        try {
            $response = $this->client->request("GET", $url, [
                "headers" => $headers,

            ]);
            return $response->getBody();
        } catch (ClientException $e) {
            return $e->getResponse()->getBody();
        }
    }

    public function post($url, $headers, $body)
    {
        try {
            $response = $this->client->request("POST", $url, [
                "headers" => $headers,
                "json"    => $body,
            ]);
            return $response->getBody();
        } catch (ClientException $e) {
            return $e->getResponse()->getBody();
        }
    }

}

所有作曲家依赖项都已安装,但一直出错,有人有解决方案吗?

标签: phpjsonapicurlguzzle

解决方案


你试过没有请求方法吗?

$this->client->post($url, []);

您使用的是哪个版本的 guzzle?


推荐阅读