none
How to use HttpClient or HttpWebRequest to consume Https (Secure) web services in Windows Phone 8.1 RT RRS feed

  • Question

  • Hi

    I am new in Windows Phone Programming. I have to consume https (Secure) web services in my Windows Phone 8.1 Run time app. I have tried lot but getting error Server not found exception. I have waste my one week for this but still not getting response from server. 

    Please help me to solve this issue. I am using Postman Rest Client of Google chrome to check web services. I am getting response in Postman but trough HttpClient or HttpWebRequest getting Server not found exception.

    Please find the attached screenshot for your reference having URL with data and Header (GET Request). Please share me code for this. I will be very thankful if any one solve this problem.

    Thanks in advance...

      

    Thursday, November 13, 2014 12:40 PM

Answers

  • Hi Friends,

    Finally I got answer to solve secure web services having SSL issue. I have install WinRtHttpClientHandler package which you can install from Nuget (Install-Package WinRtHttpClientHandler). Afer this add below code.

    var filter = new HttpBaseProtocolFilter();
    filter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.Untrusted);
    var client = new System.Net.Http.HttpClient(new WinRtHttpClientHandler(filter));

     HttpResponseMessage aResp = await client.GetAsync("Paste your Url here");
     string result = await aResp.Content.ReadAsStringAsync();

    For this I have worked one week but finally feeling happy after solving my issue.



    Tuesday, November 18, 2014 7:06 AM

All replies

  • Hello,

    Please download this full example from Microsoft: https://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664/file/98924/10/HttpClient%20sample.zip

    Just one question: have you tried to access the URI via Browser?

    Thursday, November 13, 2014 12:51 PM
  • Thanks for your prompt reply..I have tried Uri via browser and getting below response

    {"errorCode":"401","errorMessage":"Please provide an APIKey."}

    Because we have to add X-API-Key in header..I have already download this Sample Code.But not solve my problem.

    Question : In android app they have added certificate to validate https request..We have to add certificate in windows Phone?

    If you have any idea please share me. Please try to solve my problem. I have shared Postman screenshot to you.

    Thanks..

     
    Thursday, November 13, 2014 1:37 PM
  • OK, I suggest you to address your question directly to Google Forum in this case. Yesterday I tried to help an user and we faced the same problem. https://social.msdn.microsoft.com/Forums/vstudio/en-US/118b723f-ceaf-49ab-93ec-c8349426550b/direct-rest-call-to-google-api?forum=csharpgeneral#92a4c47c-726c-4e08-8cad-e6e7b9850ea9

    I would like to suggest to try adding the header in your request and trying to see the result.

    httpWebRequest.Headers.Add("X-API-Key", "yourAPIKey");
    Another test your can do is to turn on a network profiler to trace the request from Postman that works. My best suggestion is to use Fiddler. http://www.telerik.com/download/fiddler

    Thursday, November 13, 2014 1:55 PM
  • Hi Friends,

    Finally I got answer to solve secure web services having SSL issue. I have install WinRtHttpClientHandler package which you can install from Nuget (Install-Package WinRtHttpClientHandler). Afer this add below code.

    var filter = new HttpBaseProtocolFilter();
    filter.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.Untrusted);
    var client = new System.Net.Http.HttpClient(new WinRtHttpClientHandler(filter));

     HttpResponseMessage aResp = await client.GetAsync("Paste your Url here");
     string result = await aResp.Content.ReadAsStringAsync();

    For this I have worked one week but finally feeling happy after solving my issue.



    Tuesday, November 18, 2014 7:06 AM