MCPcopy Create free account
hub / github.com/bcvgh/daydayEXP / getCoon

Method getCoon

src/main/java/com/bcvgh/utils/HttpTools.java:145–182  ·  view source on GitHub ↗
(String url)

Source from the content-addressed store, hash-verified

143 }
144
145 private static HttpURLConnection getCoon(String url) throws IOException, NoSuchProviderException, NoSuchAlgorithmException, KeyManagementException {
146 SSLContext sslcontext = SSLContext.getInstance("SSL", "SunJSSE");
147 TrustManager[] tm = new TrustManager[]{new Cert()};
148 sslcontext.init((KeyManager[])null, tm, new SecureRandom());
149 HostnameVerifier ignoreHostnameVerifier = new HostnameVerifier() {
150 public boolean verify(String s, SSLSession sslsession) {
151 LOGGER.debug("WARNING: Hostname is not matched for cert.");
152 return true;
153 }
154 };
155 HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier);
156 HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());
157 URL url_object = new URL(url);
158
159// HttpURLConnection conn = (HttpURLConnection)url_object.openConnection();
160// 代理
161 HttpURLConnection conn = null;
162 Proxy proxy = (Proxy) SetProxyController.proxySetting.get("proxy");
163 if(proxy != null) {
164 conn = (HttpURLConnection)url_object.openConnection(proxy);
165 }
166 else {
167 conn = (HttpURLConnection)url_object.openConnection();
168 }
169
170 conn.setRequestProperty("User-Agent", UA);
171 conn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
172 conn.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9");
173 conn.setRequestProperty("Connection","close");
174
175 conn.setConnectTimeout(8000);
176 conn.setReadTimeout(8000);
177 conn.setDoOutput(true);
178 conn.setDoInput(true);
179 conn.setUseCaches(false);
180 conn.setInstanceFollowRedirects(false);
181 return conn;
182 }
183
184 private static String streamToString(InputStream inputStream, String encoding) {
185 String resultString = null;

Callers 2

getMethod · 0.95
postMethod · 0.95

Calls 3

initMethod · 0.80
getMethod · 0.80
openConnectionMethod · 0.80

Tested by

no test coverage detected