Recover response from a post using guzzle

Asked

Viewed 285 times

1

I’m trying to catch the answer of a porst json with the guzzle in a simple php.

This is the function in a Laravel project that posts to a url. (I’m using var_dump to show the result in the terminal).

public function getPhotos($properties)
{
    $codes = [];
    foreach($properties as $property)
    {
        $codes[$property['codigo']] = $property['cod_filial'];
    }
    $client = new Client();
    $response = $client->request('POST', 'http://local.app/file2.php', ['json' => \GuzzleHttp\json_encode($codes)]);
    var_dump($response); exit;
}

This is the php file mapped to http://local.app/file2.php

<?php
$input = file_get_contents('php://input');;
$input = json_decode($input);
echo $input;

The Guzzle restores me empty. Can anyone help me? Thank you

  • 2 different language and does not receive value at the same time, use $.ajax can help. Take the example: http://answall.com/questions/144032/redirecionar-p%C3%A1gina-passageResponse-do-ajax-para-uma-div/144050#144050

  • But they are not different languages. Both are php.

  • I understand, but this using PDO? no and yet 2 language are different.

  • I got it. I just had to modify the $response for : $response->getBody()->getContents().

  • Good Ivan! You can close or delete ;)

1 answer

0

I got it. I just had to modify the $response for : $response->getBody()->getContents().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.