何时引发HttpStatusCodeException异常? [英] When HttpStatusCodeException exception raised?

查看:397
本文介绍了何时引发HttpStatusCodeException异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用下面的代码时,出现HttpStatusCodeException异常的情况是什么.

when i use below code , what is the case to get HttpStatusCodeException exception .

ResponseEntity<Object> response = 
  restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, Object.class);

请任何人帮忙????????

Please can anyone help out ????????

推荐答案

HTTP状态代码是服务器的响应,因此,如果您控制服务器,则可以使其返回所需的任何错误.如果您无法控制服务器,则可以尝试发送错误/无效请求,以便服务器发出投诉.

HTTP Status Codes are responses from the server, therefore if you have control of the server then you could make it return whichever errors you want. If you don't have control of the server then you could try sending bad/invalid requests so that the server will complain.

在服务器端这样的事情:

Something like this on your server side:

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity getAnError() {
    // complain!
    return ResponseEntity.status(HttpStatus.FORBIDDEN);
}

这篇关于何时引发HttpStatusCodeException异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆