1 明明是get请求报错为post请求 (这个问题已经坑了我两次了)
package com.dianrong.rbms.common.client.matrix;import com.dianrong.rbms.common.client.matrix.result.ReportResult;import feign.Headers;import feign.Param;import feign.RequestLine;/** * @author: wangjun * @create: 2018-06-29 **/public interface MatrixClient { @Headers({"Content-Type: application/json", "Accept: application/json"}) @RequestLine("GET /api/v3/phone/getReport?ssn={ssn}&phone={phone}") ReportResult getReport(@Param("ssn") String ssn, @Param("phone") String phone);}
报错 :
Exception in thread "main" feign.FeignException: status 405 reading Mongo#findSingleArchiveByDeviceId2(String,String,String); content:{"timestamp":1488507926013,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/api/v3/phone/getReport"} at feign.FeignException.errorStatus(FeignException.java:62) at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:91) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:134) at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76) at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103) at com.sun.proxy.$Proxy4.findSingleArchiveByDeviceId2(Unknown Source) at com.chinamobile.iot.App.main(App.java:18) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
提示"Request method 'POST' not supported
" 找GET是否配置错误,找不到原因 最后结果是 @Herders里边的键值对冒号后面必须有个空格 @Headers("key: {value}")
另外,如果GET方法有一堆参数: 想要设置一个request实体类,把所有参数都包进去,放到HTTP 的body来上传,也会被当成POST。一句话:GET参数不支持复杂对象(只支持String、Integer这些简单对象)