final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
//Trust every server - dont check for any certificate
private static void trustAllHosts() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
URL url = new URL(effectiveUrl);
if (url.getProtocol().toLowerCase().equals("https")) {
trustAllHosts();
HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
https.setHostnameVerifier(DO_NOT_VERIFY);
connection = https;
} else {
connection = (HttpURLConnection) url.openConnection();
URL url = new URL("http://haat.cn/DAQgE");
URLConnection conn = url.openConnection();
((HttpURLConnection) conn).setInstanceFollowRedirects(false);//Location header 302
String val = conn.getHeaderField("Location");
System.out.println(val);
分享到:
相关推荐
A Visual Studio 2013 project which shows how to use the Entity Framework 6 in an ASP.NET MVC 5 web application project, using the Code First development approach. The previous version that uses EF 5 ...
SQL Window could display an incorrect elapsed time Window List no longer brings window to front when closing a window with Shift-Click or Ctrl-Click Changing a window with Ctrl-Tab, Ctrl-Shift-Tab and...
Traffic is encrypted by default over all IPOP connections, with no granularity in enabling or disabling it. This research proposes and implements the feature of selective security, in which only a ...
Backend Certificate and Hostname Validation 254 HTTP Strict Transport Security 254 Content Security Policy 255 Protocol Downgrade Protection 255 9. Performance Optimization . . . . . . . . . . . . . ....
With an effortless integration that deploys perfectly into pre-existing workflows, Odin allows you to serialize anything and enjoy Unity with 80+ new inspector attributes, no boilerplate code and so ...
- FIX: In THistory.DeleteActions added validation of FActionIndex (FActionIndex could appear beyond the list boundaries). Thanks to Giedrius Matonis. - ADD: Added the method TCustomProp.Assign - a ...
approaches to privacy protection that involve the temporary or permanent disabling of RFID technology may introduce a security vulnerability because of the potential for these mechanisms to be used in...
Schizophrenia remains a common and frequently disabling illness that poses enormous challenges for affected individuals, their families, mental health care providers, healthcare systems, and society ...
In our example, if one transaction (T1) holds an exclusive lock at the table level, and another transaction (T2) holds an exclusive lock at the row level, each of the transactions believe they have ...
Reading an Unbuffered Character in a Cross-Platform Way Recipe 2.24. Counting Pages of PDF Documents on Mac OS X Recipe 2.25. Changing File Attributes on Windows Recipe 2.26. Extracting Text ...
Enabling/disabling of delays is configured in the code by commenting/uncommenting the following lines of code: ;; 2 lines below enable rising and falling edge delays #define RISING_EDGE_DELAY #define...
logback常用配置,包含debug、info、warn、error、界别的配置,输出到文件,按照日期建立文件夹
An option disabling direct connections, see property DisableDirectConnections[*] Direct connections are estabilished now through proxy (if any)[*] Removed thread layer while resolving IPs in SOCKS ...
see Appendix D: Disabling Cryptographic Algorithms in Java PKI Programmer's Guide and Disabled Cryptographic Algorithms in Java Secure Socket Extension (JSSE) Reference Guide. Various enhancements ...
日志(logback)
In case you get any build errors that you think might be caused by the Build Report Tool, try disabling the Build Report Window from showing automatically whenever you build. You can do this by ...
While lots of Windows NT settings can be changed through the registry, disabling the Lock Workstation button in the Windows NT Security (Ctrl-Alt-Del) dialog seems to be forgotten. This program ...
When Goto is invoked on an external type in XAML, VA prompts to open the Object Browser (instead of searching it without prompting). (case=96541) Find Symbol in Solution dialog lists symbols defined ...
ary 9Oish-character tweetable Boot application to an in-depth analysis of Boots Actuator in chapter 7, which enables a host of auto-magical operational features required for any production application...
With an effortless integration that deploys perfectly into pre-existing workflows, Odin allows you to serialize anything and enjoy Unity with 80+ new inspector attributes, no boilerplate code and so ...