当使用 Spring Boot 中的 RestTemplate 进行 HTTP 请求时,可以通过捕获 HttpServerErrorException 异常来获取非 200 状态码的响应体内容。
// 发起Http请求 String url = happayConfig.getApiHost().concat(apiPath); ResponseEntity<String> response = null; try { response = restTemplate.postForEntity(url, entity, String.class); } catch (HttpServerErrorException ex) { String error = "调用某瓜支付异常:HTTP状态码为:" + ex.getRawStatusCode() + ",响应内容为:" + ex.getResponseBodyAsString(); System.out.println("接口返回信息:"); System.out.println(ex.getResponseBodyAsString()); BusinessException.of(error); } // 返回Response_body return response.getBody();
public class test { public static void main(String[] args) { &...
public class test { public static void main(String[] args) { &...
(1).java睡眠函数Thread.sleep(时间); //单位为毫秒(2).java睡眠函数例子Date dNow = new Date(); SimpleDateFormat ft = new&nbs...
System.out.println("当前时间戳(秒): " + System.currentTimeMillis()/1000); System.out.println("当前时间戳(毫秒): " +&nb...
java匹配一个字符串在另外一个字符串中出现的次数,java正则start,java正则end// 正则 String pattern = "\\bgao\\b"; // 字符串 String content ...
java命令行传参,java从命令行接收参数public static void main(String[] args) { for (int i = 0;&nb...