I have the following CURL Request to an API: curl -X POST -H "X-Api-Key:somekey" --data "name=myname&email=test@test.com" https://api.test.com/accounts
What is the Equivalent script to use in GuzzleHTTP Psr7. I tried the following but didn't work, it didn't receive the $query data array.
$query = [
'name'=>'MyName',
'email'=>'Email@think-ds.com',
];
$client = new Client([
'base_uri' => 'https://api.test.com/v1/',
'verify' =>'cert.pem',
]);
$headers=['form_params'=>$query];
try{
$request = new Request('POST', 'accounts', $headers);
$response = $client->send($request);
} catch (\GuzzleHttp\Exception\ClientException $e) {
die($e->getResponse()->getBody()->getContents()); exit;
}
var_dump($response->getBody());