【发布时间】: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 请求中?)