C# 在Windows phone 8.1中发布到服务时从HRESULT:0x80072F0D获取异常

C# 在Windows phone 8.1中发布到服务时从HRESULT:0x80072F0D获取异常,c#,windows-phone-8.1,windows-8.1,httpclient,C#,Windows Phone 8.1,Windows 8.1,Httpclient,当我试图在Windows Phone 8.1中使用HttpClient将数据发布到API时,我总是从HRESULT:0x80072F0D异常中获得异常。在fiddler中,它工作得很好 try { var requestbody="json data" HttpClient httpClient = new HttpClient(); HttpRequestMessage msg = new HttpRequestMessage(new HttpMethod("POS

当我试图在Windows Phone 8.1中使用HttpClient将数据发布到API时,我总是从HRESULT:0x80072F0D异常中获得
异常。在fiddler中,它工作得很好

try
{  
    var requestbody="json data"
    HttpClient httpClient = new HttpClient();
    HttpRequestMessage msg = new HttpRequestMessage(new HttpMethod("POST"), new Uri(addressUri));
    msg.Content = new HttpStringContent(requestbody);
    msg.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
    HttpResponseMessage response = await httpClient.SendRequestAsync(msg).AsTask();
}           
catch (Exception ex)
{
    getting **Exception from HRESULT: 0x80072F0D**
}
请告诉我出了什么问题

---供参考----

要获取有关HRESULT代码的更多信息,请执行以下操作


这看起来像是与证书相关的问题。也许您正在使用SSL。虽然许多程序在没有明确必要的情况下(例如浏览器)优雅地覆盖丢失的证书,
HttpClient
对此非常敏感

您应该尝试下载正在使用的连接的证书,并将证书文件存储在资产文件夹中。当应用程序启动时,将其推入证书存储。这是我在我的一个应用程序中使用的一个片段。也许这会让你的例外消失

请在此处阅读更多信息:


您可以使用以下代码绕过此错误:

var baseFilter = new HttpBaseProtocolFilter();
baseFilter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.InvalidCertificateAuthorityPolicy);
var httpClient = new HttpClient(baseFilter);
不过,这只会消除错误,而不是解决问题。我不太了解SSL错误,这可能不是一个安全的选择,也可能无法通过应用程序认证。根据报告:

只有在高级方案中才应忽略SSL服务器证书错误。忽略归类为可忽略或致命的服务器证书错误可能会导致通过SSL会话传递的内容的隐私或完整性丢失


遇到0x80072efd问题。我花了几个小时甚至几天来解决这个问题。提供即时解决方案的解决方案是来自管理命令提示符的以下命令:


netsh winhttp重置代理

收到与原始发件人相同的错误。我不使用代理

这对我有用。netsh winhttp重置代理
下一个传真发送无误。

您使用的是哪个
HttpClient
。异常消息是什么?仅供参考,HRESULT为WININET_E_INVALID_CA“证书颁发机构无效或不正确”。@Fred我正在Windows Phone 8.1 xaml中使用Windows.Web HttpClientproject@DecadeMoon那么,我需要澄清什么?或者我需要用这个做什么?在fiddler中,它工作正常。我使用相同的url和相同的post data.https?可能是ssl证书问题?这很有意义。如果需要,我将与我们的服务器团队核实是否提供证书。而且,在Windows Phone项目中,我必须将“InvalidCertificateAuthorityPolicy”改为“Untrusted”,否则将引发有关未知选项值的异常。
// Add our custom certificate
try
{
    // Read the contents of the Certificate file
    System.Uri certificateFile = new System.Uri("ms-appx:///Assets/ca.cer");
    Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(certificateFile);
    Windows.Storage.Streams.IBuffer certBlob = await Windows.Storage.FileIO.ReadBufferAsync(file);

    // Create an instance of the Certificate class using the retrieved certificate blob contents
    Windows.Security.Cryptography.Certificates.Certificate rootCert = new Windows.Security.Cryptography.Certificates.Certificate(certBlob);

    // Get access to the TrustedRootCertificationAuthorities for your own app (not the system one)
    Windows.Security.Cryptography.Certificates.CertificateStore trustedStore = Windows.Security.Cryptography.Certificates.CertificateStores.TrustedRootCertificationAuthorities;

    // Add the certificate to the TrustedRootCertificationAuthorities store for your app
    trustedStore.Add(rootCert);
}
catch (Exception oEx)
{
   // Catch that exception. We don't really have a choice here..
   var msg = oEx.Message;
}
var baseFilter = new HttpBaseProtocolFilter();
baseFilter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.InvalidCertificateAuthorityPolicy);
var httpClient = new HttpClient(baseFilter);