0
点赞
收藏
分享

微信扫一扫

okHttp3,springBoot,postMan 不兼容问题


   趁这个空隙,将之前的一个问题记录一下。

   问题描述:

             后台使用spring-webMvc搭建快速的后台接口,形如(注意,方法应该是post,我这里是随便截取的一个示例,用以说明问题,实体参数对象没有做任何特殊的注解):

okHttp3,springBoot,postMan 不兼容问题_上传

           当使用 postMan传输时,形如:

okHttp3,springBoot,postMan 不兼容问题_上传_02

okHttp3,springBoot,postMan 不兼容问题_spring-webMvc_03

  上传,属性能够被正确的封装,解析。 

     使用okHttp3,爱用标准定呃json格式传输,后台不能正确解析, 不能获取到对象。 

问题解决:

     在springMvc后台使用  @RequestBody,注解目标参数实体对象。  okHttp3传输可正确解析。  然,postMan相同的方式传输失效;  正确使用如下:

okHttp3,springBoot,postMan 不兼容问题_上传_04

   上传之后, 后台能够正确解析对象。 

问题思考:

       postMan以表单方式提交的时候,实际上提交的是formdata类型,springMvc在默认情况下,能够从formdata属性中注入到实体对象。    而 formdata方式提交的数据时,其是不能设置: contentType的。    换言之,我们在postman设置的header并未生效。 

  参考:​​FormData的使用以及用ajax提交的注意事项​​

okHttp3,springBoot,postMan 不兼容问题_spring_05

  问题延申——postMan几种请求方式的区别:

         参考:​​POSTMAN HTTP请求的四种方式区别​​

okHttp3,springBoot,postMan 不兼容问题_mvc_06

  对应: 

okHttp3,springBoot,postMan 不兼容问题_mvc_07

             

okHttp3,springBoot,postMan 不兼容问题_mvc_08

okHttp3,springBoot,postMan 不兼容问题_上传_09

 对应:   

okHttp3,springBoot,postMan 不兼容问题_spring_10

okHttp3,springBoot,postMan 不兼容问题_mvc_11

okHttp3,springBoot,postMan 不兼容问题_spring_12

    问题延申——后台对数据格式的处理初探:

参考: ​​Postman中POST方式使用form-data和raw作为body发起请求理解​​  

okHttp3,springBoot,postMan 不兼容问题_mvc_13

okHttp3,springBoot,postMan 不兼容问题_spring_14

    

okHttp3,springBoot,postMan 不兼容问题_spring-webMvc_15

okHttp3,springBoot,postMan 不兼容问题_mvc_16

okHttp3,springBoot,postMan 不兼容问题_spring_17

   

okHttp3,springBoot,postMan 不兼容问题_mvc_18

okHttp3,springBoot,postMan 不兼容问题_spring-webMvc_19

 

 

举报

相关推荐

0 条评论