当前位置: 首页 > news >正文

wordpress加载媒体库谷歌seo最好的公司

wordpress加载媒体库,谷歌seo最好的公司,如何注册域名赚钱,仁寿网站建设根据basic auth请求https获取token 对接第三方接口,给了接口文档,但是没有示例代码,postman一直可请求成功,java就是不行。百思不得其解,最后请求公司大神,得到一套秘籍。 第一步 第二步 Authorization&am…

根据basic auth请求https获取token


对接第三方接口,给了接口文档,但是没有示例代码,postman一直可请求成功,java就是不行。百思不得其解,最后请求公司大神,得到一套秘籍。

第一步

在这里插入图片描述
第二步
在这里插入图片描述
Authorization:Bearer access_token。其中,Bearer为固定字符串,后面包含一个空格,access_token表示实际获取到的token。

第三步:写出代码。


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.spcp.platform.common.util.StringUtil;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.springframework.http.*;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;public String getToken() {String token = "";try {TrustStrategy acceptingTrustStrategy = (x509Certificates, authType) -> true;SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslFactory).build();HttpComponentsClientHttpRequestFactory factory =new HttpComponentsClientHttpRequestFactory();factory.setConnectTimeout(3600000);factory.setReadTimeout(3600000);factory.setHttpClient(httpClient);RestTemplate restTemplate = new RestTemplate(factory);// 要请求的URLString requestUrl = "https://110:39/oauth/token?grant_type=client_credentials";// header根据实际情况设置,没有就空着MultiValueMap<String, String> params = new HttpHeaders();params.add("grant_type", "client_credentials-aqjc");HttpHeaders headers = new HttpHeaders();// 加密后的用户名和密码,这个替换成加密后的headers.add("Authorization", "Basic d2666666666666==");//headers.add("Content-Type", "application/x-www-form-urlencoded");HttpEntity<?> requestEntity = new HttpEntity<>(params, headers);// 发送请求并接收响应ResponseEntity<String> response = restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, String.class);// 获取响应体String responseBody = response.getBody();// 输出响应体内容Map<String, String> resMap = new ObjectMapper().readValue(responseBody, new TypeReference<Map<String, String>>() {});token = resMap.get("access_token");} catch (Exception e) {e.printStackTrace();}return token;}

总结:其实挺难的,尤其https认证。

http://www.hkea.cn/news/103445/

相关文章:

  • 网上商城网站建设意义在线代理浏览网页
  • 网站图片切换代码百度下载并安装最新版
  • 微信公众平台号申请注册入口杭州seo公司
  • 本周实时热点新闻事件seo文章代写一篇多少钱
  • 旺店通app手机企业版下载网站seo如何优化
  • 宝山区建设用地事务所网站网络公司有哪些
  • 用sql做简单的博客网站大连谷歌seo
  • 新手怎么学做网站就业培训机构有哪些
  • magento网站建设搭建网站步骤
  • 营销网站如何实现差异化南京seo公司
  • 服务器托管是啥搜索引擎优化排名培训
  • 山西手机网站建设网址大全123
  • b2c平台有哪些平台网址新区seo整站优化公司
  • WordPress突然全站404网站如何添加友情链接
  • 复制别人网站做第一站seo短视频网页入口引流下载
  • 基层建设论文收录在哪个网站百度统计api
  • 购买主机可以做网站吗楚雄今日头条新闻
  • 深圳专业网站建设公司哪家好宁波网络营销公司
  • ps做电商网站流程图百度图片识别搜索引擎
  • 做电影网站程序好用武汉网站建设推广公司
  • 如何做b2c网站下列关于友情链接说法正确的是
  • 网站开发中网页上传seo在线网站推广
  • 网站建设报价流程免费培训网站
  • 聊城网站建设服务好最新网域查询入口
  • 一般网站建设流程有哪些步骤官方百度app下载安装
  • 档案网站建设的步骤八大营销方式有哪几种
  • 手机网站免费制作平台semseo
  • 周口市做网站小红书seo排名
  • 网站开始怎么做的ps培训
  • 去哪个网站找题目给孩子做保定百度首页优化