Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Problem sending json data from node js to php using axios

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?.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!