Otávio Barreto
Otávio Barreto

Reputation: 1558

PHP Guzzle Call to undefined method

I am trying to use this github repository https://github.com/otaviobarreto/dlocal-php but I am getting a error on Guzzle

Call to undefined method GuzzleHttp\Client::request()

Here is the php code:

<?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();
        }
    }

}

All composer dependences was already installed but it keeps getting error, does somebody have a solution?

Upvotes: 0

Views: 1892

Answers (1)

kamil.w
kamil.w

Reputation: 144

Did you try without request method ?

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

Which version of guzzle you're using ?

Upvotes: 1

Related Questions