在使用http请求工具如(fiddler、postman),报错Content type 'application/octet-stream' not supported
原因是后端(即自己开发的后端工程),不支持Content type 为'application/octet-stream'的http请求。
解决方式是,在发起http请求的时候,在header中,手动添加Content type属性。如:Content-type: application/json
原理是:
后端在获取http请求中body里(即只针对post请求,因为只有post请求才有body,get请求是没有body的)参数的时候(现在基本都不要自己写代码来响应http请求了,都交给框架来实现了,如spring mvc、spring boot等),要先看http request的header中的Content type是什么,然后再去对应的解析参数。因为有可能body中的参数格式可能是:
1)file格式,即文件的二进制代码
https://blog.csdn.net/android_freshman/article/details/51910937
2)form格式,即最终body里的是这种格式:key1=val1&key2=val2
3)json格式
1、如果不指定Content type,后端不知道该如何解析request传递过来的参数。
即不知道该用什么规则去解析request传递过来的参数。
2、Content-type是针对post请求的,get不用指定Content-type。
https://blog.csdn.net/bingqinshuiyin/article/details/52749400?locationNum=1