Content-Type,内容类型,一般是指网页中存在的Content-Type,用于定义网络文件的类型和网页的编码,决定文件接收方将以什么形式、什么编码读取这个文件,这就是经常看到一些Asp网页点击的结果却是下载到的一个文件或一张图片的原因。


form 表单发请求:

浏览器在封装请求头的时候:

要先写上content-type 编码格式


POST时才有请求体,浏览器的request请求中,请求体格式:

1、json   2、formdata  3、x-www-form-urlencoded(默认的)

application/formdata

上传文件的时候用,格式:

POST http://www.example.com HTTP/1.1
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryrGKCBY7qhFd3TrwA ------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="user" yuan
------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="file"; filename="chrome.png"
Content-Type: image/png PNG ... content of chrome.png ...
------WebKitFormBoundaryrGKCBY7qhFd3TrwA--

application/x-www-form-urlencoded(默认的)

格式:name=yuan&pwd=123

ajax 发请求:

发送json方式请求体,要做什么:

$.ajax({
... data:json.stringify({ a:1,b:2 })
contentType:"application/json" ....
})

request.post 存放的是解析后的请求体信息,request.post只解析urlencoded的类型

此处发的json类型的数据,所以在view层,不能解析json数据,通过request.post拿不到数据

request.body里放的是请求里的原信息

此时我们想要拿到数据,需要通过 request.body,自己解析请求体数据,

#在Django中获取body中数据,并转换编码格式
json.loads(request.body.decode('utf8))

这样写将json转成urlencoded格式的数据,也可以解决该方法

$.ajax({
...

// 将json转成urlencoded格式的数据
data:{xxx:json.stringify({ a:1,b:2 })}
     contentType:"application/json"
        ....
})
 

HTTP 之 Content-Type的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  8. springboot 报错 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    开始 controller 方法写的是 @RequestMapping( value = "/add", method = RequestMethod.POST ) public ...

  9. .NET获取文件的MIME类型(Content Type)

    第一种:这种获取MIME类型(Content Type)的方法需要在.NET 4.5之后才能够支持,但是非常简单. 优点:方便快捷 缺点:只能在.NET 4.5之后使用 public FileResu ...

  10. 万能的ctrl+shift+F(Element 'beans' cannot have character [children], because the type's content type is element-only.错误)

    今天在spring-servlet.xml文件中出现了一个莫名其妙的错误:Element 'beans' cannot have character [children], because the t ...

随机推荐

  1. 快速搭建springboot工程

    一.创建SpringBoot的三种方式 在线创建: https://start.spring.io 在IntelliJ IDEA中选择Spring Initializr创建:或者在Eclipse中选择 ...

  2. WPF之复选MVVM TreeView(TreeView+CheckBox)

    需求背景: 当我们用到权限菜单栏时权限菜单栏属于递归效果,我们需要用到TreeView+CheckBox进行组合复选开发时,我们需要解决此类问题时怎么办,那么就引出今天的小笔记内容 实现方式: 下载M ...

  3. C#使用 WebRequest 异步获取网页并自动忽略SSL证书

    C#使用 WebRequest 模拟浏览器请求访问网页并自动忽略HTTPS安全证书 以下两个C#异步方法,封装了WebRequest请求,支持忽略SSL证书. 作者:张赐荣 1.Get请求      ...

  4. MHA + Maxscale 数据库的高可用和读写分离

    MySQL 常见发行版本 MySQL 标准化.自动化部署 深入浅出MySQL备份与恢复 深入理解MySQL主从复制 MySQL构架设计与容量规划 MHA Maxscale MySQL 常见发行版本 M ...

  5. 案例二:shell脚本获取当前日期和时间及磁盘使情况

    习题分析 本题有两个核心知识点: 1. 如何自动表示当天的日期 2. 磁盘使用情况 打印日期的命令为 date,示例命令如下: # date 2017 年 12 月 20 日 星期三 16:26:55 ...

  6. Windows Server 2012 在桌面上显示”我的电脑”

    转至:https://jingyan.baidu.com/article/f25ef2544f6883482c1b82e5.html Windows Server 2012 沒有快捷方式显示我的电脑到 ...

  7. idea教程--快速插入依赖

    1.打开pom.xml文件,按下快捷键Alt+insert,弹出Generate框,选择Dependency. 2.搜索所需jar的关键字. 3.点击add.添加jar包成功.如果第二步没有所要jar ...

  8. kibana实现条件查询和修改

    GET jyb_report_index_preprod/_search { "query": { "match": { "report_id&quo ...

  9. python爬虫之抓取小说(逆天邪神)

    2022-03-06 23:05:11 申明:自我娱乐,对自我学习过程的总结. 正文: 环境: 系统:win10, python版本:python3.10.2, 工具:pycharm. 项目目标: 实 ...

  10. Qt:QMap

    0.说明 QMap < Key , T > 一个QMap就是一个K-V对,也可以说是字典对象. 1)构造 构造一个Key是QString,Value是int的QMap: QMap<Q ...