-1

)

I have issue with Laravel 5.2 and Guzzle 6.3

This is my code for sending POST to URL

    $client = new Client();
    $result = $client->post('https://marketing.webbera.co.uk/form/2', [
    'form_params' => [
        'mauticform_label_welcomeemailwebbera_email' => 'test@test.com',
        'mauticform_label_welcomeemailwebbera_ime' =>'Secret'
    ]
]);

$result = $client->send($result);

And this is error that I have

Argument 1 passed to GuzzleHttp\Client::send() must implement interface Psr\Http\Message\RequestInterface, instance of GuzzleHttp\Psr7\Response given, called in /app/Http/Controllers/Registration.php on line 63 and defined

This is line 63 $result = $client->send($result);

I don't have clue what can be wrong so any hint is welcome ;)

Josh Miller
  • 1
  • 1
  • 1

3 Answers3

0

You should check the guzzle 6 docs.

You have already made a post request by this:

$response = $client->post('http://httpbin.org/post');

The send method is used when you make a request instance. The results are the same.

$request = new Request('POST', 'http://httpbin.org/post');
$response = $client->send($request);
Ben
  • 5,069
  • 4
  • 18
  • 26
0

In earlier versions of guzzle $client->post() was creating Request object which needs to be password as an argument to send method to actually make a request , But in guzzle 6 $client->post will do the job in one-shot

So you can remove your last line , and use response object returned by $client->post

Raaghu
  • 1,956
  • 1
  • 19
  • 17
0

The $client->request function is responsible for sending the data and you can control the status with $response->getStatusCode()

use GuzzleHttp\Client;
$client = new Client();
    $response = $client->request('POST', 'https://marketing.webbera.co.uk/form/2', [
      'form_params' => [
        'mauticform_label_welcomeemailwebbera_email' => 'test@test.com',
        'mauticform_label_welcomeemailwebbera_ime' =>'Secret'
      ],
      'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
      ],
    ]);

    if ($response->getStatusCode() != 200) {
      throw new \Exception('Error with status code: ' . $response->getStatusCode() . 'and body: ' . $response->getBody()->getContents());
    }