Getting exception from HRESULT: 0x80072F0D when submitting to service in Windows 8.1 phone

When I try to send data to the API using HttpClient on Windows Phone 8.1, I always get an exception Exception from HRESULT: 0x80072F0D

. In fiddler, it works great.

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**
}

      

Please tell me what went wrong?

--- FYI ----

For more information on HRESULT code, follow these steps: WebErrorStatus enumeration

  var exceptionDetail = WebError.GetStatus(ex.GetBaseException().HResult);

  if (exceptionDetail == WebErrorStatus.HostNameNotResolved)
  {
    //
  }

      

+3


source to share


3 answers


It looks like a certificate issue. You may be using SSL. While many programs gracefully override missing certificates if they are clearly not needed (like browsers), it is HttpClient

quite sensitive to this.

You should try to download the certificate for the connection you are using and save the certificate file in your resources folder. When your application starts, paste it into the certificate store. This is a snippet that I am using in one of my applications. Perhaps this is throwing your exception.



More details here: http://blogs.msdn.com/b/wsdevsol/archive/2014/06/05/including-self-signed-certificates-with-your-windows-runtime-based-windows-phone-8-1 -apps.aspx

// 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;
}

      

+6


source


Perhaps you can work around the error with this code:

var baseFilter = new HttpBaseProtocolFilter();
baseFilter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.InvalidCertificateAuthorityPolicy);
var httpClient = new HttpClient(baseFilter);

      



It just silences the error , not a solution to the problem. I am not very well versed with SSL errors and this might be a safe option and may not get app certified. According to the docs :

SSL server certificate errors should only be ignored in advanced scenarios. Failure to comply with server certificate errors classified as Ignorable or Fatal may result in loss of confidentiality or integrity of the content transmitted over the SSL session.

+1


source


Tried issue 0x80072efd. It cost me hours, if not days, to decide. The solution that gave instant permission is the following command from the admin command prompt:

netsh winhttp reset proxy

-1


source







All Articles