We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
指http发送信息至服务器时的内容编码类型。就是该请求的里面的信息是图片还是html文件啥的,用于告诉服务器和浏览器怎么解析该请求重的数据。本文主要介绍该字段与在ajax请求中常用的三个值: application/x-www-form-urlencoded, multipart/form-data, application/json
application/x-www-form-urlencoded
multipart/form-data
application/json
Content-Type:application/json name=ming&sex=male
FormData对象没有像JSON.stringify那样的方法能批量将对象形式转换为对应的形式
let userObj = {userName: ’xxx', age: '21'} formData.append('user', userObj) ------WebKitFormBoundaryyb1zYhTI38xpQxBK Content-Disposition: form-data; name="user" [object Object]
如需正常转换需手动实现转换函数或者借助qs库
var obj = { a: '2', b: {c: 'test'}, c: [ {id: 1, name: 'xx'}, {id:2 ,name: 'yy', info: {d: 4} } ] } a: 2 b[c]: test c[][id]: 1 c[][name]: xx c[][id]: 2 c[][name]: yy c[][info][d]:4
请求体被分割成多部分,每部分使用 --boundary分割;
... Content-Type: multipart/form-data; boundary=${boundary} --${boundary} ... ... --${boundary}--
Content-Type: application/x-www-form-urlencoded {"name": "ming", "sex":"male"}
对于一些复制的数据对象,对象里面再嵌套数组的话,建议使用application/json。json的形式的优点是它可以传递结构复杂的数据形式,但是json不支持二进制数据,必须转义二进制数据。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
HTTP常见字段之 Content-Type
字段含义
指http发送信息至服务器时的内容编码类型。就是该请求的里面的信息是图片还是html文件啥的,用于告诉服务器和浏览器怎么解析该请求重的数据。本文主要介绍该字段与在ajax请求中常用的三个值:
application/x-www-form-urlencoded
,multipart/form-data
,application/json
application/x-www-form-urlencoded
Content-Type:application/json
name=ming&sex=male
FormData对象没有像JSON.stringify那样的方法能批量将对象形式转换为对应的形式
如需正常转换需手动实现转换函数或者借助qs库
multipart/form-data
请求体被分割成多部分,每部分使用 --boundary分割;
json
Content-Type: application/x-www-form-urlencoded
{"name": "ming", "sex":"male"}
对于一些复制的数据对象,对象里面再嵌套数组的话,建议使用application/json。json的形式的优点是它可以传递结构复杂的数据形式,但是json不支持二进制数据,必须转义二进制数据。
The text was updated successfully, but these errors were encountered: