javascript Axios 与请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46749408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 06:53:48  来源:igfitidea点击:

Axios vs Request

javascriptnode.jsrequestaxios

提问by Rohit Behera

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

我正在对带有一些表单数据的URL进行发布请求......我有兴趣捕获响应中的“命令”:“插入”部分......

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

当我使用AXIOS向 url发帖时。我没有得到这个“命令”:“插入”部分

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

butwhen I make a call to the same URLusing the same form variables BUT using request. I get the "command":"insert"part

但是当我使用相同的表单变量 BUT 使用request调用相同的URL 时。我得到 “命令”:“插入”部分

 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.

这是我放在 RequireBin 上的演示。请在 mozilla 或 Cors 禁用的 Chrome 上运行。

采纳答案by glhrmv

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.

这似乎是axios处理 POST 请求的问题Content-Type: application/x-www-form-urlencodedaxios的 GitHub 页面中有一个未解决的问题,提供了一些讨论和可能的解决方法