网站做排名,wordpress百科,嘉兴做外贸网站比较好的公司,欧亚快递100简介:Content-Type(MediaType)#xff0c;即是Internet Media Type#xff0c;互联网媒体类型#xff1b;也叫做MIME类型#xff0c;在Http协议消息头中#xff0c;使用Content-Type来表示具体请求中的媒体类型信息.参考response.Header里常见Content-Type一般有以下四种即是Internet Media Type互联网媒体类型也叫做MIME类型在Http协议消息头中使用Content-Type来表示具体请求中的媒体类型信息.参考response.Header里常见Content-Type一般有以下四种application/x-www-form-urlencodedmultipart/form-dataapplication/jsontext/xml详解:1.application/x-www-form-urlencodedapplication/x-www-form-urlencoded是最常见的Content-Type,form表单默认提交方式对应的content-type.当action为get时候浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1value1name2value2...)然后把这个字串追加到url后面用?分割加载这个新的url.当action为post,且表单中没有typefile类型的控件时,Content-Type也将采用此编码方式,form数据将以key:value键值对的方式传给server.表单提交:后台:import java.io.Serializable;public class Student implements Serializable {private String name;private String hobby;private int age;public String getName() {return name;}public void setName(String name) {this.name name;}public String getHobby() {return hobby;}public void setHobby(String hobby) {this.hobby hobby;}public int getAge() {return age;}public void setAge(int age) {this.age age;}}RequestMapping(value /test, method RequestMethod.POST)public String test(Student student) {System.out.println(student.getName());return /test1;}2.multipart/form-data当post表单中有typefile控件时content-type会使用此编码方式.表单提交:后台:RequestMapping(value /test, method RequestMethod.POST)public String test(Student student,RequestParam(value file1, required false) MultipartFile file1) {System.out.println(student.getName());return /test1;}3.application/json随着json规范的流行,以及前后端分离趋势所致,该编码方式被越来越多人接受.前后端分离后,前端通常以json格式传递参数,因此该编码方式较适合RestfulApi接口.前端传参:$.ajax({url: /test,type: POST,data: {name: zhangsan,age: 12,hobby: football},dataType: json,success: function (date) {}})后台:RequestMapping(value /test, method RequestMethod.POST)public String test(RequestBody Student student) {System.out.println(student.getName());return /test1;}4.text/xmlXML-RPC(XML Remote Procedure Call)。它是一种使用 HTTP 作为传输协议XML 作为编码方式的远程调用规范。soapUI等xml-rpc请求的参数格式.提交参数:zhangsan12footbal分类: java