2017-03-27 786 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? –

相關問題