有java 代码 现在要转换成C# 代码 ,主要是第二段代码改如何转换 最好有核心代码列举一下,不胜感激
public class Authentication { @SuppressWarnings("resource") public static void main(String args[]) throws Exception { HttpsUtil httpUtils = new HttpsUtil(); httpUtils.initSSLConfigForTwoWay(); //Two-Way Authentication String appId = "c5999872-f6e0-4663-8946-c2ff8b2baae0"; //please replace the appId, when you use the demo. String secret = "875eadb27b0fc4df5a6f"; //please replace the secret, when you use the demo. String url = "https://******"; //please replace the IP and Port, when you use the demo. Map<String, String> param = new HashMap<String, String>(); param.put("appId", appId); param.put("secret", secret); String body = httpUtils.doPostFormUrlEncodedForString(url, param); System.out.println(body); }
HttpsUtil
public void initSSLConfigForTwoWay() throws Exception { // 1 Import your own certificate KeyStore selfCert = KeyStore.getInstance("pkcs12"); selfCert.load(new FileInputStream(SELFCERTPATH), SELFCERTPWD.toCharArray()); KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509"); kmf.init(selfCert, SELFCERTPWD.toCharArray()); // 2 Import the CA certificate of the server, 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); // 3 Set the domain name to not verify // (Non-commercial IoT platform, no use domain name access generally.) SSLSocketFactory ssf = new SSLSocketFactory(sc, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); //If the platform has already applied for a domain name which matches the domain name in the certificate information, the certificate //domain name check can be enabled (open by default) // SSLSocketFactory ssf = new SSLSocketFactory(sc); ClientConnectionManager ccm = this.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 8743, ssf)); httpClient = new DefaultHttpClient(ccm); }
c#官方的代码是不能通过的,基本上写法和java一致才能通过(跳过)验证,照到上面改就行了,就是一些大小写及个别单词不一样。
能不能把主要用到的几个类型 列举一下 步骤肯定是跟着写没问题,但是现在问题是对应不上C#中的类
@zklveyjx: 怎么可能,原本就是invoke java。