I was wondering if anyone could point me in the right direction. We setup an api that will take a curl request such as
curl -X 'POST' 'url target' -H 'accept: application/json' -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=some_user_name&password=some_password
Trying to write ethe request in symfony 6, it seems like i'm setting it up wrong and not placing the -d data into the correct area. It doesn't appear to go into the user_data field as i get an error 422 back from the server.
$response = $this->client->request('POST', $url_target, [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
],
'verify_peer' => false,
'verify_host' => false,
'data' => 'username=some_user_name&password=some_password'
]);
I was wondering if someone could point me in the right direction as i'm pretty sure i'm doing something stupid.
CodePudding user response:
You need to pass your data in the body
parameter:
$response = $this->client->request('POST', '', [
// other params ...
'body' => ['username' => 'some_user_name', 'password' => 'some_password']
]
);