I need to do a PUT request on my API in my PHP application. If I execute the request from Postman, it works but not from the website. I use the default Apache for MacOSX BigSur.
So in postman, the request works.
In my browser, I have an Error 400 Bad Request
Here is the code.
<?php
$curl = curl_init();
$id = $_GET['id'];
$brandId = $_GET['brandId'];
$model = $_GET['model'];
$inventoryNumber = $_GET['inventoryNumber'];
$comment = $_GET['comment'];
//exported code from Postman
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost/api/computer/$id?brandid=$brandId&model=$model&inventoryNumber=$inventoryNumber&comment=$comment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"Postman-Token: 41213077-2a5d-4dc4-bee6-f0c683de5f3c",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
//header('Location: http://localhost/computer/');
}
I don't understand why it works from postman and not from the browser. I also checked the LimitRequestFieldSize but changing it doesn't do anything. I also have GET, DELETE and POST request but they work perfectly.
source https://stackoverflow.com/questions/67925684/put-request-works-in-postman-but-not-in-browser
No comments:
Post a Comment