I'm trying to send POST data from a Chrome extension to a website controlled by me. However, when sending the POST data I don't receive any.
I'm sending it using this function:
async function httpPost(url, data) {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
return response.json();
}
It is being called like so:
const post = await httpPost("https://example.com/api", extracted);
Where extracted
contains something similar to {entries: [], total: 0 }
.
I've tried console.log
on httpPost
, response
, post
which did not gave anything useful besides that they're working correct.
On the server side, doing a isset
for $_POST
does work. The request is sending and is being received. However, doing file_put_contents('test.txt', print_r($_POST));
leaves the file empty. It is being accessed, just empty.
CORS Headers are set:
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 1000");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: *");
header('Content-Type: application/json');
What could this very frustrating issue be?
Desired output: Being able to receive the POST data that I sent with httpPost
.