How is an HTTP POST request made in node.js?

后端 未结 21 2400
南方客
南方客 2020-11-21 23:54

How can I make an outbound HTTP POST request, with data, in node.js?

21条回答
  •  终归单人心
    2020-11-22 00:35

    Posting another axios example of an axios.post request that uses additional configuration options and custom headers.

    var postData = {
      email: "test@test.com",
      password: "password"
    };
    
    let axiosConfig = {
      headers: {
          'Content-Type': 'application/json;charset=UTF-8',
          "Access-Control-Allow-Origin": "*",
      }
    };
    
    axios.post('http://:/', postData, axiosConfig)
    .then((res) => {
      console.log("RESPONSE RECEIVED: ", res);
    })
    .catch((err) => {
      console.log("AXIOS ERROR: ", err);
    })

提交回复
热议问题