Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("main") 'Load the layout file.
MainForm.Show
nativeMe = Me
nativeMe.RunMethod("initSSLConfig",Null)
htp.Initialize ("hp",Me)
htp.PostString("https://192.168.0.3:8743/iocm/app/sec/v1.1.0/login","appId=f8fc0c83 & secret=18498bde")
htp.GetRequest.SetContentType("application/x-www-form-urlencoded")
End Sub
#If Java
import java.io.*;
import java.security.KeyStore;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class HttpsClientDemo extends DefaultHttpClient {
public String SELFCERTPATH = "D://work/software/B4j/20180314Test/cert/CertwithKey.pkcs12";
public String SELFCERTPWD = "IoM@1234";
public String TRUSTCAPATH = "D://work/software/B4j/20180314Test/cert/ca.jks";
public String TRUSTCAPWD = "Huawei@123";
public void initSSLConfigForTwoWay() throws Exception {
KeyStore selfCert = KeyStore.getInstance("pkcs12");
selfCert.load(new FileInputStream(SELFCERTPATH), SELFCERTPWD.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
kmf.init(selfCert, SELFCERTPWD.toCharArray());
KeyStore caCert = KeyStore.getInstance("jks");
caCert.load(new FileInputStream(TRUSTCAPATH), TRUSTCAPWD.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509");
tmf.init(caCert);
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
SSLSocketFactory ssf = new SSLSocketFactory(sc);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 8743));
}
}
public void initSSLConfig(){
HttpsClientDemo httpClient2 = new HttpsClientDemo();
httpClient2.initSSLConfigForTwoWay();
}
#End If