If you need to request via JS to https across domains, here are two ways:
The first one: $.getjson should be added in the URL behind the callback=?
Note: The HTTPS server that is being accessed must return JSON data.
If you can not change the server, we can do it on the client, use the following second method
The second type:
private static class Trustanytrustmanager implements X509trustmanager {
public void checkclienttrusted (x509certificate[] chain, String authtype)
Throws Certificateexception {
}
public void checkservertrusted (x509certificate[] chain, String authtype)
Throws Certificateexception {
}
Public x509certificate[] Getacceptedissuers () {
return new x509certificate[] {};
}
}
@SuppressWarnings ("deprecation")
private static class Trustanyhostnameverifier implements Com.sun.net.ssl.HostnameVerifier {
@Override
public boolean Verify (String arg0, string arg1) {
return true;
}
}
public void Activei2000keeplive () {
InputStream is = null;
PrintWriter pw = null;
try {
Sslcontext sc = sslcontext.getinstance ("SSL");
Sc.init (NULL, new trustmanager[] {new Trustanytrustmanager ()},
New Java.security.SecureRandom ());
String Remoteurl = Initaction.remote_url;
Final String url = remoteurl.substring (0,remoteurl.indexof ("/", 8)) + "/servlet/keeplive";
URL console = new URL (URL);
Javax.net.ssl.HttpsURLConnection conn = (httpsurlconnection) console.openconnection ();
Com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl conn = (Httpsurlconnectionoldimpl) Console.openconnection ();
Conn.setsslsocketfactory (Sc.getsocketfactory ());
Conn.sethostnameverifier (New Trustanyhostnameverifier ());
Conn.connect ();
is = Conn.getinputstream ();
DataInputStream indata = new DataInputStream (IS);
String ret = "";
String Str_return = "";
while (ret!= null) {
ret = Indata.readline ();
if (ret!= null &&!ret.trim (). Equals ("")) {
Str_return = Str_return
+ New String (Ret.getbytes ("iso-8859-1"), "GBK");
}
}
System.out.println (Str_return);
PW = Servletactioncontext.getresponse (). Getwriter ();
if (is!= null) {
Pw.write ("Success");
}else{
Pw.write ("error");
}
Conn.disconnect ();
catch (Connectexception e) {
}catch (Exception e) {
}
finally {
try {
if (is!= null) {
Is.close ();
}
if (PW!= null) {
Pw.close ();
}
catch (IOException e) {
}
}
}