12
12
13
13
import com .tencent .xinge .api .RESTAPI_V3 ;
14
14
15
+ import javax .net .ssl .HostnameVerifier ;
16
+ import javax .net .ssl .HttpsURLConnection ;
17
+ import javax .net .ssl .SSLSession ;
18
+
15
19
/**
16
20
* 提供V3接口<br>
17
21
* 1. v3中appId是String类型,v2中是long <br>
@@ -70,7 +74,7 @@ public JSONObject deviceTag(String jsonRequest) {
70
74
private JSONObject callRestful (String apiAddress , String jsonRequestString ) {
71
75
72
76
URL url ;
73
- HttpURLConnection http = null ;
77
+ HttpsURLConnection http = null ;
74
78
InputStreamReader isr = null ;
75
79
BufferedReader br = null ;
76
80
String ret = "" ;
@@ -80,7 +84,8 @@ private JSONObject callRestful(String apiAddress, String jsonRequestString) {
80
84
try {
81
85
url = new URL (null , apiAddress , new com .sun .net .ssl .internal .www .protocol .https .Handler ());
82
86
URLConnection con = url .openConnection ();
83
- http = (HttpURLConnection ) con ;
87
+ http = (HttpsURLConnection ) con ;
88
+ http .setHostnameVerifier (new TrustAnyHostnameVerifier ());
84
89
http .setRequestMethod (RESTAPI_V3 .HTTP_POST );
85
90
http .setDoOutput (true );
86
91
http .setRequestProperty ("Authorization" , "Basic " + authStringEnc );
@@ -151,4 +156,11 @@ public static String stringifyError(Throwable error) {
151
156
return result .toString ();
152
157
}
153
158
159
+ public class TrustAnyHostnameVerifier implements HostnameVerifier {
160
+ public boolean verify (String hostname , SSLSession session ) {
161
+ // 直接返回true
162
+ return true ;
163
+ }
164
+ }
165
+
154
166
}
0 commit comments