博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OAuth2.0 https
阅读量:5810 次
发布时间:2019-06-18

本文共 1978 字,大约阅读时间需要 6 分钟。

/**	 * OAuth 认证	 * @throws Exception	 */	public String requestYimallOAuth() throws Exception {				TrustManager[] trustAllCerts = new TrustManager[] {				   new X509TrustManager() {				      public java.security.cert.X509Certificate[] getAcceptedIssuers() {				        return null;				      }				      public void checkClientTrusted(X509Certificate[] certs, String authType) {  }				      public void checkServerTrusted(X509Certificate[] certs, String authType) {  }				   }				};					SSLContext sc;			sc = SSLContext.getInstance("SSL");						sc.init(null, trustAllCerts, new java.security.SecureRandom());			HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());			// Create all-trusting host name verifier			HostnameVerifier allHostsValid = new HostnameVerifier() {			    public boolean verify(String hostname, SSLSession session) {			      return true;			    }			};			// Install the all-trusting host verifier			HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);						URL url = new URL("");//  你要请求的地址			HttpsURLConnection httpsURLConnection=(HttpsURLConnection)url.openConnection();			httpsURLConnection.setConnectTimeout(30000);			httpsURLConnection.setReadTimeout(30000);			httpsURLConnection.setDoOutput(true);			httpsURLConnection.setDoInput(true); 			httpsURLConnection.setUseCaches(true);   			httpsURLConnection.setRequestMethod("POST");			httpsURLConnection.connect();			int responseCode=httpsURLConnection.getResponseCode();			InputStream input=null;			if(responseCode==200){				input=httpsURLConnection.getInputStream();			}else{				input=httpsURLConnection.getErrorStream();			}			BufferedReader in = new BufferedReader(new InputStreamReader(input));			StringBuilder result=new StringBuilder();			String line=null; 			while((line=in.readLine())!=null){				result.append(line);			}						String access_token = result.toString();			System.out.println(access_token);			return "success";	}

  

转载于:https://www.cnblogs.com/jayGold/p/3487876.html

你可能感兴趣的文章
10g手动创建数据库
查看>>
Windwos Server 2008 R2 DHCP服务
查看>>
UVa 11292 勇者斗恶龙(The Dragon of Loowater)
查看>>
白话算法(7) 生成全排列的几种思路(二) 康托展开
查看>>
d3 v4实现饼状图,折线标注
查看>>
微软的云策略
查看>>
Valid Parentheses
查看>>
【ES6】数值的扩展
查看>>
性能测试之稳定性测试
查看>>
ES6的 Iterator 遍历器
查看>>
2019届高二(下)半期考试题(文科)
查看>>
【REDO】删除REDO LOG重做日志组后需要手工删除对应的日志文件(转)
查看>>
nginx 301跳转到带www域名方法rewrite(转)
查看>>
AIX 配置vncserver
查看>>
windows下Python 3.x图形图像处理库PIL的安装
查看>>
【IL】IL生成exe的方法
查看>>
network
查看>>
SettingsNotePad++
查看>>
centos7安装cacti-1.0
查看>>
3个概念,入门 Vue 组件开发
查看>>