spring boot http 404 400的错误处理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/learner198461/article/details/86678562

有个外面外包公司开发的CRM系统,我们对接时候发现会有http404 400错误,是用spring boot RestTemplate开发,在请求时候会产生异常。异常后返回值不能获取。

在异常情况需要这么处理,在post动作时候,捕捉异常,捕捉异常处理httpclienterrorexception类型的类,这个有个getreponsestring方法可以获取返回值。简单代码

try{

    调用http请求

catch(httpclienterrorexception ex){

 ex.getresponsestring();

}

猜你喜欢

转载自blog.csdn.net/learner198461/article/details/86678562