项目用到阿里的身份证接口: 身份证实名认证查询接口
我喜欢使用feign来请求项目外部的接口, 定义feign接口, feign设置headers的教程请参考(Spring 使用 feign时设置header信息):
@FeignClient(url = "${identity.host}",
name="identity",
fallbackFactory = IdenFallbackFactory.class,
configuration = {FeignLogConfigurer.class}
)
public interface IdenauthenFeignClient {
@RequestMapping(value = "/idenAuthentication",
method = RequestMethod.POST,
headers = {"Content-Type=application/x-www-form-urlencoded",
"charset=UTF-8",
"Authorization=APPCODE ${identity.appcode}"
})
String getIden(@RequestParam(value = "memberIdNo") String idNo, @RequestParam(value = "memberRealName") String name) throws Exception;
}
请求的时候就报了feign.FeignException: status 450 reading Idenauthen FeignClient错误, 网上没有这类错误出现, 我仔细看了一下feign打印日志:
x-ca-error-message: Required argument idNo : expect [type: String]
发现传参问题有问题
@FeignClient(url = "${identity.host}",
name="identity",
fallbackFactory = IdenFallbackFactory.class,
configuration = {FeignLogConfigurer.class}
)
public interface IdenauthenFeignClient {
@RequestMapping(value = "/idenAuthentication",
method = RequestMethod.POST,
headers = {"Content-Type=application/x-www-form-urlencoded",
"charset=UTF-8",
"Authorization=APPCODE ${identity.appcode}"
})
String getIden(@RequestParam(value = "idNo") String idNo, @RequestParam(value = "name") String name) throws Exception;
}
再次请求一下, 搞定