【问题标题】:Windows App service: HTTP works, but not HTTPS (vb.net or c#)Windows 应用服务:HTTP 有效,但 HTTPS 无效(vb.net 或 c#)
【发布时间】:2015-10-23 02:30:46
【问题描述】:

我正在构建一个 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 回读的 sResult 中存储的错误是:错误 80190194 消息:未找到 (404)。响应状态码不表示成功:404(未找到)。
  • 出于好奇,如果您请求具有有效的非自签名证书的 https 页面,只是为了测试它,您是否会遇到同样的失败? (IE,您是否确认它仅发生在自签名证书或所有 https 请求中?)

标签: c# .net vb.net windows


【解决方案1】:

出现此问题的原因可能是自签名证书并非源自受信任的来源,并且某些浏览器将其理解为网络钓鱼网站 - 可能是 Cortana 理解它并阻止了连接。

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

请确保您的证书是由机器而不是网站查看的(如果使用 IIS7 及更高版本)。

【讨论】:

    猜你喜欢
    • 2019-07-01
    • 2013-05-05
    • 2012-03-10
    • 1970-01-01
    • 2014-06-15
    • 2013-11-02
    • 2016-08-11
    • 1970-01-01
    • 2013-03-15
    相关资源
    最近更新 更多