zoukankan      html  css  js  c++  java
  • Content-type的几种常见类型

    1、application/x-www-form-urlencoded

       1)浏览器的原生form表单
       2)提交的数据按照 key1=val1&key2=val2 的方式进行编码,key和val都进行了URL转码

    POST [http://www.example.com](http://www.example.com) HTTP/1.1 
    Content-Type: application/x-[www-form-urlencoded](http://www-form-urlencoded);charset=utf-8 
    
    title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3 
    2、multipart/form-data

       常见的 POST 数据提交的方式。我们使用表单上传文件时,必须让 form 的 enctype 等于这个值。

    <form action="/" method="post" enctype="multipart/form-data">
      <input type="text" name="description" value="some text">
      <input type="file" name="myFile">
      <button type="submit">Submit</button>
    </form>

       请求头看起来像这样

    POST /foo HTTP/1.1
    Content-Length: 68137
    Content-Type: multipart/form-data; boundary=---------------------------974767299852498929531610575
    
    ---------------------------974767299852498929531610575
    Content-Disposition: form-data; name="description"
    
    some text
    ---------------------------974767299852498929531610575
    Content-Disposition: form-data; name="myFile"; filename="foo.txt"
    Content-Type: text/plain
    
    (content of the uploaded file foo.txt)
    ---------------------------974767299852498929531610575--
    3、application/json

       消息主体是序列化后的 JSON 字符串,这个类型越来越多地被大家所使用

    POST [http://www.example.com](http://www.example.com) HTTP/1.1 
    Content-Type: application/json;charset=utf-8 
    
    {"title":"test","sub":[1,2,3]}
    4、text/xml

       是一种使用 HTTP 作为传输协议,XML 作为编码方式的远程调用规范

    POST [http://www.example.com](http://www.example.com) HTTP/1.1 
    Content-Type: text/xml 
    <!--?xml version="1.0"?--> 
    <methodcall> 
        <methodname>examples.getStateName</methodname> 
        <params> 
            <param> 
                <value><i4>41</i4></value> 
        </params> 
    </methodcall> 

    5.其他

    text/html  :HTML格式
    text/plain :纯文本格式      
    text/xml   :XML格式
    
    image/gif  :gif图片格式    
    image/jpeg :jpg图片格式 
    image/png  :png图片格式
    
    application/xml     : XML数据格式
    application/json    : JSON数据格式
    application/pdf     : pdf格式  
    application/msword  : Word文档格式
    application/octet-stream : 二进制流数据(如文件下载)
    
    application/x-www-form-urlencoded : 
    
    <form encType="">中默认的encType,
    form表单数据被编码为key/value格式发送到服务器(表单默认的提交数据的格式)。
    服务器收到的raw body会是,name=aaa&key=bbb。
    
    multipart/form-data : 表单上传文件
  • 相关阅读:
    从对比学习(Contrastive Learning)到对比聚类(Contrastive Clustering)
    国际学术会议英文口头报告(Oral presentation)常用语句
    物以类聚人以群分:聚类分析的一些挑战和进展
    多视图子空间聚类/表示学习(Multi-view Subspace Clustering/Representation Learning)
    关于“Unsupervised Deep Embedding for Clustering Analysis”的优化问题
    【Swift】TableView显示多列数据,锁定第一列位置
    【Swift】 WKWebView https 加载不受信任的站点
    【Swift】Starscream 实现socket连接
    【Swift】GRDB数据库本地存储聊天记录
    【Swift/Objective-c】公司项目优化(二)
  • 原文地址:https://www.cnblogs.com/mzhaox/p/11263946.html
Copyright © 2011-2022 走看看