2 years ago

Connect API with Laravel project

Posted 2 years ago by aleksov

I need to connect to an API with my Laravel 5.1 project so I write function to test:

public function testDng() {

    $client = new GuzzleHttp\Client(['verify' => false ]);
try {
    $res = $client->post('', [

    'form_params' => [
        'email' => '[email protected]',
        'password' => 'asdasd'
return $res;
catch (GuzzleHttp\Exception\ClientException $e) {
        $response = $e->getResponse();
        $result =  json_decode($response->getBody()->getContents());

    return response()->json(['data' => $result]);



The result of this function is:


but when I try this API in Postman app everything is fine and I get token:

So something is wrong with my function ... What caused the problem and why I cant get token?

Please sign in or create an account to participate in this conversation.