Spring Post Using RestTemplate
来源:互联网 发布:spine 3.6 mac 破解版 编辑:程序博客网 时间:2024/05/22 03:42
@Override public String getAlerts() { try { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); headers.add("Authorization", "Bearer eyJrIjoickpreElnY2dRWXF6Nk10SW1XNlVIQW10eTN2YWpJVHIiLCJuIjoid2FuZGEtZWRpdG9yIiwiaWQiOjF9"); HttpEntity<String> entity = new HttpEntity<>("parameters", headers); Object response = restTemplate.exchange("http://localhost:9009/api/alerts?dashboardId=1", HttpMethod.GET, entity, Object.class); System.out.println(response); return response.toString(); } catch (Exception e) { System.out.println(e); return e.getMessage(); } }
@Override public void pauseAlert(int alertId) { try { String pause_msg = "{\r\n" + " \"paused\": true\r\n" + "}"; String unpause_msg = "{\r\n" + " \"paused\": false\r\n" + "}"; HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); headers.add("Authorization", "Bearer eyJrIjoickpreElnY2dRWXF6Nk10SW1XNlVIQW10eTN2YWpJVHIiLCJuIjoid2FuZGEtZWRpdG9yIiwiaWQiOjF9"); HttpEntity<String> entity = new HttpEntity<>(pause_msg, headers); Object response = restTemplate.exchange( String.format("http://localhost:9009/api/alerts/%d/pause?", alertId), HttpMethod.POST, entity, Object.class); System.out.println("pause alert = " + response); entity = new HttpEntity<>(unpause_msg, headers); response = restTemplate.exchange(String.format("http://localhost:9009/api/alerts/%d/pause?", alertId), HttpMethod.POST, entity, Object.class); System.out.println("unpause alert = " + response); } catch (Exception e) { System.out.println(e); } }
private void anotherPostAlert(int alertId) { try { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); headers.add("Authorization", "Bearer eyJrIjoickpreElnY2dRWXF6Nk10SW1XNlVIQW10eTN2YWpJVHIiLCJuIjoid2FuZGEtZWRpdG9yIiwiaWQiOjF9"); Map<String, Object> params = new HashMap<String, Object>(); params.put("paused", true); HttpEntity<Map<String, Object>> entity = new HttpEntity<>(params, headers); Object response = restTemplate.exchange( String.format("http://localhost:9009/api/alerts/%d/pause?", alertId), HttpMethod.POST, entity, Object.class); System.out.println("another pause alert = " + response); } catch (Exception e) { System.out.println("another pause alert = "+ e); } }
阅读全文
0 0
- Spring Post Using RestTemplate
- Spring RestTemplate Post with Header
- Spring Resttemplate post方法踩坑记录
- RestTemplate post
- spring RestTemplate
- spring restTemplate
- Spring RestTemplate
- 使用RestTemplate发送post请求
- REST In Spring : RestTemplate
- Spring RestTemplate Json 例子
- spring RestTemplate用法详解
- Spring restTemplate 超时配置
- spring的RestTemplate
- spring RestTemplate用法详解
- 使用Spring RestTemplate测试
- Spring RestTemplate 实践
- spring RestTemplate用法详解
- Spring RestTemplate详解
- EEGLAB数据分析:预处理与后续处理
- MySQL系列(一)---基础知识大总结
- palindrome-number
- 机器学习:逻辑回归原理及实现代码
- Error:Execution failed for task ':app:transformClassesWithDexForDebug'解决记录
- Spring Post Using RestTemplate
- 2017暑假训练第七天
- 动态库和静态库的区别
- 自定义View移动圆点详解
- 在使用Java的Properties时,修改数值后会发生顺序的改变
- 笔记9:Linux 文件系统编程
- Python3.x连接Pymysql
- How to keep CoreBluetooth connection alive between views
- POJ