Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在一个客户端上执行两个HTTPS POST调用-Java到Vb.Net_Java_Vb.net_Post_Https - Fatal编程技术网

在一个客户端上执行两个HTTPS POST调用-Java到Vb.Net

在一个客户端上执行两个HTTPS POST调用-Java到Vb.Net,java,vb.net,post,https,Java,Vb.net,Post,Https,我需要使用HTTPS POST调用登录到一个站点,然后执行另一个POST调用以执行操作 我已经编写了一个用Java执行此任务的方法,但是现在我需要在VB.NET中切换我的应用程序,我不能使用JVM、Java类或类似的工具 这是我的方法: private static void disableSslVerification() { try{ // Create a trust manager that does not validate certificate chains Tru

我需要使用HTTPS POST调用登录到一个站点,然后执行另一个POST调用以执行操作

我已经编写了一个用Java执行此任务的方法,但是现在我需要在VB.NET中切换我的应用程序,我不能使用JVM、Java类或类似的工具

这是我的方法:

private static void disableSslVerification() {
try{
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        public void checkClientTrusted(X509Certificate[] certs, String authType) {
        }

        public void checkServerTrusted(X509Certificate[] certs, String authType) {
        }
    } };

    // Install the all-trusting trust manager
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

    // Create all-trusting host name verifier
    HostnameVerifier allHostsValid = new HostnameVerifier() {
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };

    // Install the all-trusting host verifier
    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
} catch (KeyManagementException e) {
    e.printStackTrace();
}
(避免ssl验证)

但是,当我执行MessageBox.Show()方法时,他给了我“System.aggregateeexception”错误,消息是“发生了一个或多个错误”


任何人都可以帮我一下吗?

错误可能是由于未处理的异常。用try/catch块包装web请求代码

Try
    here put web request code

Catch wex As WebException
    If TypeOf wex.Response Is HttpWebResponse Then
        MsgBox(DirectCast(wex.Response, HttpWebResponse).StatusCode)
    End If

    other web exception handling

Catch ex As Exception
    other exception handling

End Try
还记得将web请求放在与UI线程不同的线程上,以避免阻塞它

我使用此代码使帖子广告始终有效:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 'This is for enabling SSL/TLS support
mWebClient = New WebClient()

Dim reqparm As New Specialized.NameValueCollection
reqparm.Add("username", login.username)
reqparm.Add("password", login.password)

Dim responsebytes = mWebClient.UploadValues("https://1.2.3.4/Login", "POST", reqparm) '!!! I don't know if HTTPS is supported !!!
Dim risp = System.Text.Encoding.UTF8.GetString(responsebytes)

错误可能是由于未处理的异常造成的。用try/catch块包装web请求代码

Try
    here put web request code

Catch wex As WebException
    If TypeOf wex.Response Is HttpWebResponse Then
        MsgBox(DirectCast(wex.Response, HttpWebResponse).StatusCode)
    End If

    other web exception handling

Catch ex As Exception
    other exception handling

End Try
还记得将web请求放在与UI线程不同的线程上,以避免阻塞它

我使用此代码使帖子广告始终有效:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 'This is for enabling SSL/TLS support
mWebClient = New WebClient()

Dim reqparm As New Specialized.NameValueCollection
reqparm.Add("username", login.username)
reqparm.Add("password", login.password)

Dim responsebytes = mWebClient.UploadValues("https://1.2.3.4/Login", "POST", reqparm) '!!! I don't know if HTTPS is supported !!!
Dim risp = System.Text.Encoding.UTF8.GetString(responsebytes)

AggregateException异常不会像那样帮助您。它只是实际例外情况的一个占位符。您需要检查Handle函数或InnerExceptions属性。或者打开所有异常的中断。AggregateException异常不会像那样帮助您。它只是实际例外情况的一个占位符。您需要检查Handle函数或InnerExceptions属性。或者在所有异常上打开Break。我已经将try-catch块放在它上面,但是通过debug,我可以看到代码进入最后一个捕获,一般的捕获和ex.message是“发生了一个或多个错误”。…如果我使用此代码进行HTTPS调用,请告诉我异常“基础连接已关闭:无法为SSL/TLS安全通道建立信任关系。“。现在我不知道是否有可能在javaWhat中安装一个类似DisablesSelfRification的假信任方法?你为什么要做这样的事??使用此行启用SSL/TLS支持
ServicePointManager.SecurityProtocol=SecurityProtocolType.Ssl3
也编辑了答案,因为目前我在该站点上没有有效的HTTPS证书:/如果我使用chrome进行此链接,他们会告诉我“站点的证书链有问题(net::ERR\u CERT\u AUTHORITY\u INVALID)”这与你的问题无关。你应该发布另一条消息并关闭它,因为我认为它现在已经解决了。我已经在它上面放置了try-catch块,但是通过debug,我可以看到代码进入了最后一个catch,一般的一个,ex.message是“发生了一个或多个错误”…如果我使用此代码进行HTTPS调用,请告诉我异常“基础连接已关闭:无法为SSL/TLS安全通道建立信任关系。“。现在我不知道是否有可能在javaWhat中安装一个类似DisablesSelfRification的假信任方法?你为什么要做这样的事??使用此行启用SSL/TLS支持
ServicePointManager.SecurityProtocol=SecurityProtocolType.Ssl3
也编辑了答案,因为目前我在该站点上没有有效的HTTPS证书:/如果我使用chrome进行此链接,他们会告诉我“站点的证书链有问题(net::ERR\u CERT\u AUTHORITY\u INVALID)”这与你的问题无关。你应该发布另一个,并关闭这个,因为我认为它现在已经解决了