Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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
Windows应用程序服务:HTTP有效,但HTTPS无效(vb.net或c#)_C#_.net_Vb.net_Windows - Fatal编程技术网

Windows应用程序服务:HTTP有效,但HTTPS无效(vb.net或c#)

Windows应用程序服务:HTTP有效,但HTTPS无效(vb.net或c#),c#,.net,vb.net,windows,C#,.net,Vb.net,Windows,我正在构建Cortana Windows 10应用程序(主要用于学习目的) 下面的代码适用于带有用户名和密码的HTTP,但HTTPS不起作用。有什么想法吗?我的服务器使用自签名证书,只输出纯文本(无HTML)。代码还可以作为Cortana访问的服务运行(不确定这是否重要,但我在将服务中的多个等待放在应用程序中时遇到了问题) 我尝试使用post命令,但无法使其工作 Dim sResult = "No server response."

我正在构建Cortana Windows 10应用程序(主要用于学习目的)

下面的代码适用于带有用户名和密码的HTTP,但HTTPS不起作用。有什么想法吗?我的服务器使用自签名证书,只输出纯文本(无HTML)。代码还可以作为Cortana访问的服务运行(不确定这是否重要,但我在将服务中的多个等待放在应用程序中时遇到了问题)

我尝试使用post命令,但无法使其工作

                        Dim sResult = "No server response."

                    ' if any values are blank, alert user to set up app
                    If sServerAddress = "" OrElse sServerPort = "" OrElse sGUID = "" Then
                        sResult = "You must open the Control Home app first, configure server settings, and then click Set Values to store server settings.  Click below to go to the app."
                    Else

                        ' TO DO: check for valid URI

                        Dim oURI As Uri = New Uri(sServerAddress + ":" + sServerPort + "/sys/%7B" + sGUID + "%7D?d??mbNaturalLanguage(" + command + ")")

                        ' the below options set up username and password, and should allow SSL certificates that are self-signed
                        Dim oFilter = New HttpBaseProtocolFilter()
                        oFilter.ServerCredential = New Windows.Security.Credentials.PasswordCredential(oURI.ToString(), sUsername, sPassword)
                        oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired)
                        oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted)
                        oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Success)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Revoked)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.IncompleteChain)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidSignature)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidCertificateAuthorityPolicy)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.BasicConstraintsError)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.UnknownCriticalExtension)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.RevocationInformationMissing)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.RevocationFailure)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.BasicConstraintsError)
                        'oFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.OtherErrors)
                        Try
                            Dim oHTTP As Windows.Web.Http.HttpClient = New Windows.Web.Http.HttpClient(oFilter)
                            sResult = Await oHTTP.GetStringAsync(oURI)
                            oHTTP.Dispose()
                            ' End If
                        Catch ex As Exception
                            sResult = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message
                        End Try
                    End If

                    ' read message
                    Await SendCompletionMessageForPhone(sResult)

出现此问题的原因可能是自签名证书并非来自可信来源,某些浏览器将其理解为仿冒网站,可能是Cortana理解并阻止了连接

我建议您购买一个便宜的SSL证书来保护您的站点,并允许您进行此类测试


确保您的证书是通过机器而不是网站(如果使用IIS7及以上版本)查看的。

忘记说存储在sResult中的错误Cortana读回的结果是:错误80190194消息:未找到(404)。响应状态代码并不表示成功:404(未找到)。出于好奇,如果您只是为了测试而请求一个带有有效、非自签名证书的https页面,您是否会遇到同样的失败?(也就是说,您是否确认只有自签名证书或所有https请求才会发生这种情况?)