【问题标题】:PHP Guzzle Call to undefined methodPHP Guzzle 调用未定义的方法
【发布时间】:2020-08-20 06:55:48
【问题描述】:

我正在尝试使用这个 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();
        }
    }

}

所有的作曲家依赖都已经安装了,但是一直报错,有人有解决办法吗?

【问题讨论】:

    标签: php json api curl guzzle


    【解决方案1】:

    你试过没有请求方法吗?

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

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

    【讨论】:

    • 我用的是guzzlehttp/guzzle5.1版本,我试试
    • $this-&gt;client-&gt;post($url, []); 给我一个Parse error
    猜你喜欢
    • 2015-11-20
    • 2012-07-27
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    相关资源
    最近更新 更多