Axios与请求 [英] Axios vs Request

查看:44
本文介绍了Axios与请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向带有某些表单数据的 URL 发出发布请求.我有兴趣捕获响应中的 "command":"insert" 部分.

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..

当我使用 AXIOS 向网址发布帖子时.我没有得到这个 "command":插入" 部分

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

但是,当我拨打相同的 URL 使用相同的表单变量,但使用请求. 我得到了 "command":插入" 部分

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

这是我放在RequireBin上的演示.

推荐答案

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

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与请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆