I have be having a hard time sending a simple multipart form request using Guzzle. For some reason I always get a 404 response but I am make the same request using cURL I get 200 ok and the data is posted.
I can't seem to figure out what the issue is even after solving a similar issue.
Here's my cURL code:
$body = shell_exec('curl -H \'Content-Type: multipart/form-data\' -H \'Accept: application/json\' \
-F "photo=@ "'.$photo.'" \
-F "api_key="'.$apiKey.'" \
-F "id=14784" \
"'.$apiUrl.'" 2>&1 > /dev/null 2>&1 &');
The shell works fine from the command line but I need to convert it to make the request from a controller so I've added the form fields to Guzzle but not I get a 404.
Here's the Guzzle code:
$guzzle = $client->request('POST', config('services.url'), [
'multipart' => [
['headers' => [
'Content-Type: multipart/form-data',
'Accept: application/json'
],
'name' => 'api_key',
'contents' => config('services.key'),
],
[
'name' => 'photo',
'contents' => $photo
],
[
'name' => 'id',
'contents' => "4084",
],
]
]);
I've changed the url for the sake of posting but I'm struggling to find the cause so if anyone knows please give me a heads up!
** EDIT ** I've been able to get past the 404 but not I get a 500 Error, not sure if it is the form or the recipient server because I can make a POST request to the same endpoint successfully with Postman.
Still baffled.