http协议中的Accept和Content-type了解

转自:https://juejin.cn/post/6923062226941132814,https://www.cnblogs.com/111testing/p/6037579.html

1.介绍 

Accept代表发送端(客户端)希望接受的数据类型。 比如:Accept:text/xml; 代表客户端希望接受的数据类型是xml类型。放在请求头中。 

Content-Type代表发送端(客户端|服务器)发送的实体数据的数据类型。 比如:Content-Type:text/html; 代表发送端发送的数据格式是html。放在实体中。  

 

如果后端接收json数据类型,post 的 headers 需要设置 { ‘content-type’: ’application/json’ },传给后端的数据就形如  { ‘name’:’edward’, ‘age’:’25’ } 

如果后端接收的是(表单)字符串类型,post 的 headers 需设置  { ‘content-type’: ’application/x-www-form-urlencoded’ },传输给后端的数据就形如   ‘name=edward&age=25’

2.常见格式

常见的媒体格式类型如下:

  •     text/html : HTML格式
  •     text/plain :纯文本格式      
  •     text/xml :  XML格式
  •     image/gif :gif图片格式    
  •     image/jpeg :jpg图片格式 
  •     image/png:png图片格式

 

posted @ 2022-11-05 20:40  lypbendlf  阅读(2357)  评论(0编辑  收藏  举报