Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda