mercredi 21 février 2018

How to use Guzzle HTTP Post method

I'm building a small application in Laravel 5.4 where I'm facing difficulties in API calls through GuzzleHttp, I'm trying to call a route in my api.php:

Route::post('/request', 'HomeController@getRequest');

and in my controller I'm calling:

public function __construct(GuzzleHttp\Client $client)
{
    $this->client = $client;
}

public function getRequest( Request $request)
{
    $request = $this->client->post($request->url, [$request->request_data]);
    $response = \GuzzleHttp\json_decode($request->getBody());
    return response()->json(['data' => json_decode($response->d)], $request->getStatusCode());
}

The data value set which I'm inserting:

{"url":"http://demo.conxn.co.in/CoxnsvcA.svc/Login","request_data":{"username":"********","password":"*******","client_secret_key":"rybbdk23dsaxxmYTHJKFHJSKksdfljsdf"}}

And I'm getting error:

error description

But while using through postman API tester, I'm getting appropriate results.

Appropriate results through postman API checker

Help me out with this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire