Axios vs Request

前提是你 提交于 2020-05-27 03:59:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/46749408/axios-vs-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!