我正在构建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)
答案 0 :(得分:0)
可能会出现此问题,因为自签名证书不是来自可信源,有些浏览器将其理解为网络钓鱼网站 - 可能是Cortana理解它并阻止连接。
我建议您购买便宜的SSL证书以保护您的网站,并允许您进行此类测试。
请确保您的证书是由机器查看的,而不是网站(如果使用IIS7及以上版本)。