POST data with request module on Node.JS

后端 未结 8 1368
青春惊慌失措
青春惊慌失措 2020-12-07 09:14

This module is \'request https://github.com/mikeal/request

I think i\'m following every step but i\'m missing an argument..

var request = require(\'         


        
相关标签:
8条回答
  • 2020-12-07 10:17

    When using request for an http POST you can add parameters this way:

    var request = require('request');
    request.post({
      url:     'http://localhost/test2.php',
      form:    { mes: "heydude" }
    }, function(error, response, body){
      console.log(body);
    });
    
    0 讨论(0)
  • 2020-12-07 10:20

    I highly recommend axios https://www.npmjs.com/package/axios install it with npm or yarn

    const axios = require('axios');
    
    axios.get('http://your_server/your_script.php')
        .then( response => {
        console.log('Respuesta', response.data);
        })
        .catch( response => {
            console.log('Error', response);
        })
        .finally( () => {
            console.log('Finalmente...');
        });
    
    0 讨论(0)
提交回复
热议问题