Content-Type指http/https发送信息至服务器时的内容编码类型,服务器根据编码类型使用特定的方式解析数据。
常用的Content-Type有:
text/html, text/plain, text/css, text/javascript, image/jpeg, image/png, image/gif,
application/x-www-form-urlencoded, multipart/form-data, application/json, application/xml
其中:text/html, text/plain, text/css, text/javascript, image/jpeg, image/png, image/gif, 是常见的页面资源类型。
application/x-www-form-urlencoded, application/json, multipart/form-data, application/xml 这四个是ajax的请求,表单提交或上传文件的常用资源类型。
方式一: 通过Form Data形式传参
默认 application/x-www-form-urlencoded, 参数格式为key=value&key=value&key=value…;
后端可以通过request.getParameter(name)的形式来获取表单参数。
方式二: 通过Request Payload形式传参
application/json以json形式传递,参数格式为JSON格式:{“key”:“value”,“key”:“value”…};对于一些复制的数据对象,对象里面再嵌套数组的话,建议使用application/json传递
后端可以使用getRequestPayload方法来获取。
作者:谢_ffd1
链接:https://www.jianshu.com/p/91fd300511cc
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。