Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
AXIOS Request does not send data to PHP server
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'));

This is my PHP server page to handle a request from a react.js client on localhost:3000

this is the code of the client

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);

}

This is the first function

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);
});

}

Of course the data are not empty and i can check using a log , if a use a third party API tool test as https://reqbin.com/ i can check my server page works fine , same thing with a React Native mobile app, but not for this React.js app

the print_r funcion , or an echo function let me see i don't recive anything

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try to pass also headers.

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda