访问第三方接口带Authorization认证
2024-09-18 21:08:31
第一种方式
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Authorization", "Bearer " + getToken());
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
RestTemplate client = new RestTemplate(requestFactory);
HttpMethod method = HttpMethod.GET;
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(null, httpHeaders);
ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class);
第二种方式
event = event.toBuilder().requestTime(time).sign(sign).build();
String jsonString = JSON.toJSONString(event);
log.info("传输给关键小事的参数是[{}]", jsonString);
Request request = new Request.Builder()
.header("Content-Type", "application/json")
.header(PARAM_APP_KEY, APP_KEY)
.header(PARAM_SIGN, sign)
.header("Authorization", getToken())
.header(PARAM_REQUEST_TIME, time + "")
.post(RequestBody.create(null, jsonString))
.url(APPOINT_ATTENDANCE_URL)
.build();
JSONObject res = JSON.parseObject(HTTPClient.sendBodyString(request));
最新文章
- .NET跨平台之旅:将QPS 100左右的ASP.NET Core站点部署到Linux服务器上
- Codeforces Round #325 垫底纪念
- 【转】JavaSript模块规范 - AMD规范与CMD规范介绍
- 架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层
- WordPress Lazy SEO插件lazyseo.php脚本任意文件上传漏洞
- C++编程规范之19:总是初始化变量
- 关于百度鹰眼中 xcode 7 编译报错问题
- android 边学边记 2015.10.16
- WPF自学笔记
- [其他]win7下chrome浏览器插件导出与导入
- PHPexcel(2)
- LeetCode 104. Maximum Depth of Binary Tree二叉树的最大深度 C++/Java
- HNOI2018游记
- GraphQL入门2
- chrome自定义ua(批处理文件方式)
- [转] Centos7 yum lock,无法上网问题,以及安装python3.5
- java 后台 post请求 携带参数 远程操作 调用接口
- qt.qpa.plugin: Could not find the Qt platform plugin ";windows"; in ";";
- JDBC删除数据库实例
- ubuntu 14.04安装OVS虚拟OpenFlow交换机配置总结