美文网首页
2019-06-27 post提交数据 编码格式问题 Cont

2019-06-27 post提交数据 编码格式问题 Cont

作者: 忙于未来的民工 | 来源:发表于2019-06-27 11:30 被阅读0次

accept:客户端告诉服务器我想要什么格式

Content-Type:客户端告诉服务器,我给你传的是什么格式的

常用的为以下三种:

1:application/x-www-form-urlencoded

这是form表单默认的提交格式,提交的参数格式类似于get请求

如果使用ajax提交post请求,需要我们将参数手动拼成get请求格式,再进行urlencode,并且需要设置请求头 

Content-Type=application/x-www-form-urlencoded;charset=utf-8

2:multipart/form-data

这种格式一般用来上传文件,form表单直接设置提交即可。

补充:js模拟表单提交

var formData =new FormData();

formData.append("msg_id", item.msgid);

formData.append("type", 3); //数字123456会被立即转换成字符串 "123456"

formData.append("uin", document.querySelector('#fxx_injector').value);

formData.append("wxdata", data);

var request =new XMLHttpRequest();

request.open("POST", webhook_url);

request.send(formData);

3:application/json

处理复杂json数据结构时,可以考虑使用这种数据传输方式。

使用ajax提交数据时,需要设置请求头

Content-Type=application/json; charset=UTF-8  

同时将需要传递的参数序列化即可(使用JSON.stringify 转成字符串)

4:text/plain

数据以纯文本的形式传递,基本不用。 Postman中标记为raw

参考:

https://imququ.com/post/four-ways-to-post-data-in-http.html

相关文章

网友评论

      本文标题:2019-06-27 post提交数据 编码格式问题 Cont

      本文链接:https://www.haomeiwen.com/subject/apulcctx.html