测试工具 调用同一个API地址,相同的入参,Postman正常,但RestTemplate一直报错:{“ErrorMessage“: “(IndexError) list index out of range“ - ,注意后面有一个空格,而RestTemplate没有此功能,必须人工声明配置"
1.问题场景
第三方API地址:http://124.AA.BBB.205:100
方式一:通过postman直接传参访问;(正常)
方式二:通过postman触发springboot的controller接口,传值后,再通过RestTemplate访问API;(报错:500 INTERNAL SERVER ERROR: "{"ErrorMessage": "(IndexError) list index out of range"}")
2.Postman直接访问正常
3.通过Postman访问springboot项目的controller层接口,再通过RestTemplate访问API报错 拼多多帮助力入口
4.问题定位及解决方法
原因:Postman在发送http请求之前,会自动在token前面加上前缀"Bearer ",注意后面有一个空格,而RestTemplate没有此功能,必须人工声明配置"Bearer token"属性,否则会报错。
问题解决。
(试过okhttp,也是一样的效果)
精彩链接