Axios vs Request

20,490

This seems to be an issue with axios' handling of POST requests with Content-Type: application/x-www-form-urlencoded. There is an open issue that offers some discussion and possible workarounds in axios' GitHub page.

Share:
20,490
Rohit Kumar
Author by

Rohit Kumar

Var Me = new Person (); When(Me.isSlept() != true){ Me.Coding() } This feature of SO is awesome...

Updated on July 09, 2022

Comments

  • Rohit Kumar
    Rohit Kumar almost 2 years

    I am doing a post request to an URL with some formdata.... I am interested in capturing the "command":"insert" part which is in the response..

    when I make a post to an url using AXIOS. I dont get this "command":"insert" part

    axios.post('https://www.localgov.ie/en/views/ajax', {  
      validation_date_from: "10/10/2017",       
      view_name : "bcsm_search_results",
      view_display_id : "notice_search_pane",
      view_path : "bcms/search"
    }).then(function(response){    
      console.log( response.data)
      console.log("--------------------------------AXIOS POST")
    }) 
    

    but when I make a call to the same URL using the same form variables BUT using request. I get the "command":"insert" part

     var formdata ={
        validation_date_from: "10/10/2017",       
        view_name : "bcsm_search_results",
        view_display_id : "notice_search_pane",
        view_path : "bcms/search"
      } ;
    
        request.post({
          url: 'https://www.localgov.ie/en/views/ajax',
          form: formdata
      },
      function (err, httpResponse, body) {
          console.log(body);       
        console.log("--------------------------------request POST")
      });
    

    Here is a demo I have put on RequireBin.. Kindly run on mozilla or Cors disabled Chrome.

  • Rohit Kumar
    Rohit Kumar over 6 years
    so does that means that I should stop using axios for posts & rather go for request ??? :o
  • A-yon Lee
    A-yon Lee over 6 years
    No, you should always use axios, its more efficient, by you have to set the request header-field to Content-type: application/json.
  • Zach Smith
    Zach Smith over 5 years
    Is that an objective answer @AyonLee? Why is axios more efficient?
  • Zeyad Shaban
    Zeyad Shaban over 3 years
    @ZachSmith Axios is 98% smaller than request in package size, see here for Axios: bundlephobia.com/[email protected] and here for request: bundlephobia.com/[email protected].