使用axios的坑

jQuery.ajaxpost提交默认的请求头的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的更多相关文章

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

  2. org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported或其他Content type不支持处理

    很久没从头到尾搭框架,今天搭的过程中,springmvc controller方法入参用@RequestBody自动绑定参数时一直提示各种 not supported 排查问题有两个解决路径: 1)使 ...

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

  4. Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...

  5. Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...

  6. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...

  7. SharePoint自动化系列——Content Type相关timer jobs一键执行

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...

  8. 转载 SharePoint【Site Definition 系列】– 创建Content Type

    转载原地址:  http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...

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

随机推荐

  1. 洛谷T21778 过年

    题目描述 有 n(1 \leq n \leq 10^5)n(1≤n≤105) 个小朋友,过年了,要发放 m(1 \leq m \leq 10^5)m(1≤m≤105) 次礼物. 每次发放,会给出三个参 ...

  2. Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心

    D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...

  3. Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp

    B. Dreamoon and WiFi 题目连接: http://www.codeforces.com/contest/476/problem/B Description Dreamoon is s ...

  4. 整理c# 不常用但有用代码

    # 整理c# 不常用但有用代码 1.winform窗体右键菜单打开其他窗体 private void contextMenuStripHandler_Click(object sender, Even ...

  5. ActiveMQ_ActiveMQ安装与配置

    ActiveMQ安装与配置   1.环境: Windows XP apache-activemq-5.2.0-bin.zip   2.安装 解压缩到apache-activemq-5.2.0-bin. ...

  6. NodeJS下的Mongodb操作

    今天用Node写一个小程序中需要用到数据库操作,试用了一下,发现官方的驱动已经非常好用了,也支持async. 一个简单的实例如下: const MongoClient = require('mongo ...

  7. 正余弦信号的DFT频谱分析

    一般的,对正余弦信号进行採样并DFT运算,画出频谱图,会发现频谱并不干净.这样的现象称为频谱泄漏.由于DFT运算仅仅能是有限序列,突然的截断产生了泄漏. 会有这种特殊情况.当採样截取的刚好是整数个周期 ...

  8. STM32 F4 Clock Sources

    STM32 F4 Clock Sources Goal: routing clock sources to the microcontroller output pin (MCO1)    High- ...

  9. ubuntu下安装ftp服务器

    参考文献: 5.4 FTP 服务器 vsftpd - FTP 服务器安装 vsftpd 是可在 Ubuntu 中使用的 FTP 守护程序之一.它在安装.设置和维护方面十分方便.要安装 vsftpd 您 ...

  10. 新玩的windows phone app studio

    其实我是一直想开发windows phone 8平台的应用的,奈何开始windows phone 8开发却是不是件容易的事.Windows phone 8的开发其实是对计算机的硬件有要求的,首先要装w ...