2017-03-27 783 views
2

使用spring cloud feign调用我的服务,当服务返回401异常时,respose.body()为空。当http代码为401时,使用spring cloud feign,respose.body()为null

当我抛出异常是throw new BadRequestException(400, “this http code is 400”);我可以得到this http code is 400response.body()的错误信息。 但是,当我抛出异常throw new BadRequestException(401, “this http code is 401”);response.body()为空。 此回复为feign.Response

为什么当http代码是401时我不能得到这个错误信息?

希望你的帮助!非常感谢你!

回答

0

切换到feign-okhttp将解决您的问题。

添加在双龙:

<dependency> 
    <groupId>com.netflix.feign</groupId> 
    <artifactId>feign-okhttp</artifactId> 
    <version>8.18.0</version> 
</dependency> 

,并添加你的配置:

feign.okhttp.enabled: true 
+0

谢谢您的回答!使用'ApacheHttpClient'也是可以的。你能告诉我为什么HttpUrlConnection关闭错误码为什么错误代码是401或407? –

相关问题