axios post提交的Content-Type
使用axios的坑
jQuery.ajax的post提交默认的请求头的Content-Type: application/x-www-form-urlencoded
而axios.post提交的请求头是Content-Type: application/json。
application/json是一个趋势,但是如果改一个旧项目,把jQuery.ajax全部换成axios.post时,需要对请求做一些配置。
改之前的代码:
// 没有指定请求头的content-type
var data = {age: 18};
$.ajax({
url: '',
type: 'POST',
data: data
dataType: 'json',
success: function(result) {
// do something
}
})
使用axios的代码
import axios from 'axios';
import qs from 'qs';
var data = {age: 18};
var url = '';
axios.post(
url,
qs.stringify(data),
{headers: {'Content-Type': 'application/x-www-form-urlencoded'}}
).then(result => {
// do something
})
axios post提交的Content-Type的更多相关文章
- the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header
the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header ...
- org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported或其他Content type不支持处理
很久没从头到尾搭框架,今天搭的过程中,springmvc controller方法入参用@RequestBody自动绑定参数时一直提示各种 not supported 排查问题有两个解决路径: 1)使 ...
- jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"的解决方法
1.报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supporte ...
- Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.
Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...
- Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.
用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...
- SharePoint自动化系列——Add content type to list.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...
- SharePoint自动化系列——Content Type相关timer jobs一键执行
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...
- 转载 SharePoint【Site Definition 系列】– 创建Content Type
转载原地址: http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...
- Springs Element 'beans' cannot have character [children], because the type's content type is element-only
Springs Element 'beans' cannot have character [children], because the type's content type is element ...
随机推荐
- preg_replace正则表达式的使用
<?php $str="as2223adfsf0s4df0sdfsdf"; echo preg_replace("/0/","",$s ...
- BZOJ2888 : 资源运输
显然资源集合处就是树的重心,这题需要动态维护树的重心. 每个连通块以重心为根,用link-cut tree维护每个点的子树大小以及子树内所有点到它的距离和. 合并两个连通块时,考虑启发式合并,暴力往大 ...
- oracle A用户访问B用户的表aa
在B中:grant select on aa to A; (还可以配置insert,update,delete权限)
- Revit Family API 添加材质参数设置可见性
start //添加类型 void AddType(FamilyManager familyMgr, string name, double w, double d) { FamilyType ...
- VC2010中"Include Directories" 和 "Additional Include Directories"的区别
右键一个Project,可以发现有两个地方设置Include的相关目录: 1. VC++ Directories -> Include Directories2. C/C++ -> Gen ...
- mormot事务控制
mormot事务控制 mormot对所有的数据库类型事务都是一样处理方法gProps.SharedTransaction(1, transBegin);try gProps.SharedTransac ...
- how to use kvo with swift (怎样在swift中使用kvo)
- FAQ:如何提高编译速度?
问: 如何提高编译速度? 答: 减少一次需要编译的代码量,目前想到的有两种思路: 1:修改解决方案的属性配置,取消勾选不常修改的项目的“生成”复选框. 2:采用插件化的架构,每一个插件弄一个解决方案, ...
- Oracle简易界面工具 (Oracle 10g, Oracle 11g)
Oracle简易界面工具 背景:偶在远程机上干活,须要调用到 Oracle 11gserver的数据,远程机上已安装Oracle client, 但 sql plus 和 sql developer ...
- ifram 取父窗体的URL地址
var url=''; try { url = window.top.document.referrer ; } catch(M) { if (window.parent) ...