This is my code in node:
var objectData= {
"metadatos":
{
"titulo": `titulo`,
"fecha": fecha,
"palabraClave":''
},
"datos":[{},{}]
};
fileContent=JSON.stringify(objectData);
axios.post('/myFile.php', fileContent)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
}); `
PHP code:
<?php
$data = json_decode(file_get_contents('php://input'), true);
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods: POST');
header('Content-Type: application/json');
print_r($data);
?>
I run the node js file from centos and get the following response:
'[AxiosError: Request failed with status code 401] { code: 'ERR_BAD_REQUEST', config: {........'
Both the node and php files are on the same server. What could be the problem?.