1
votes

So i'm testing universal applications and have reached this:

I have an application on Windows Tablet that gets data from server.

Server is protected with certificate ( SSL )

I have this code, runs great on simple Windows Store Application, and Universal application project for tablet, but not Phone

async public static Task<string> GetDataFromServer()
    {
        try
        {
            HttpClientHandler aHandler = new HttpClientHandler();
            aHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;
            HttpClient aClient = new HttpClient(aHandler);
            aClient.DefaultRequestHeaders.ExpectContinue = false;
            aClient.DefaultRequestHeaders.MaxForwards = 3;
            Uri requestUri = new Uri("MYURL");
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
            var result = await aClient.GetAsync(requestUri, HttpCompletionOption.ResponseContentRead);
            var responseHeader = result.Headers;
            var responseBody = await result.Content.ReadAsStringAsync();
            return responseBody;
        }
        catch (Exception e)
        {
            return "";
        }
    }

All needed capabilities are set in manifest:

<Capabilities>
<Capability Name="internetClient" />
<Capability Name="sharedUserCertificates" />
<Capability Name="privateNetworkClientServer" />
<Capability Name="internetClientServer" />
 </Capabilities>
 <Extensions>
<Extension Category="windows.certificates">
  <Certificates>
    <Certificate StoreName="Root" Content="Assets\CoolCertificate.cer" />
  </Certificates>
</Extension>

Phone code - doesn't crash, no errors or warnings - just blank result.

Code: {StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{ Content-Length: 0}} And no notification to the user like in WinRT:

enter image description here

3
What is the response code you get in windows phone?Prasanna Aarthi
{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{ Content-Length: 0}}Cheese
It sounds like it is not being able to connect to the server. If you try with another URI does it work? Are you sure it is a credentials problem?kiewic
How i said from the beginning when i run same app on tablet it worksCheese
Am also getting same response like {StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{ Content-Length: 0}}. Could you please help me anyone?ranjith

3 Answers

0
votes

Please use aHandler.UseDefaultCredentials= true; property and try once.hope that may solve the issue?

0
votes

Note that in Windows Phone 8.1, there's two HttpClient classes. One is inside System.Net.Http namespace, and the other Windows.Web.Http namespace.

You want to use the one in Windows.Web.Http.

0
votes

I hope you have the certificate that you need to use as PFX. In that case please refer to my reply in the link

Client Certificates Windows Phone 8.1