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

162
Views
AXIOS Request no envía datos al servidor PHP
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: PUT, GET, POST"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); print_r(file_get_contents('php://input'));

Esta es la página de mi servidor PHP para manejar una solicitud de un cliente react.js en localhost: 3000

este es el codigo del cliente

 let handleSubmitDesign = (event) => { event.preventDefault(); let url = 'https://www.myserver.com/test.php'; //Server example let data = { key: k, code: code, role: role, cat: 1 }; sendPostRequest(data, url, fun);

}

Esta es la primera función.

 function sendPostRequest(data, url, fun) { let newData = JSON.stringify(data); axios.post(url, newData) .then(function (response) { //console.log(response.data); fun(response.data); }) .catch(function (error) { console.log(error); });

}

Por supuesto, los datos no están vacíos y puedo verificar usando un registro, si uso una prueba de herramienta API de terceros como https://reqbin.com/ puedo verificar que la página de mi servidor funciona bien, lo mismo con una aplicación móvil React Native , pero no para esta aplicación React.js

la función print_r, o una función de eco déjame ver que no recibo nada

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intenta pasar también encabezados.

 function sendPostRequest(data, url, fun) { let newData = JSON.stringify(data); const headers = { "Content-Type": "application/json", //Authorization: token, Bearer token or whatever applies } axios.post(url, newData, { headers:headers }) .then(function (response) { //console.log(response.data); fun(response.data); }) .catch(function (error) { console.log(error); });
about 4 years ago · Juan Pablo Isaza Report
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!