0

We are building a WinRT app which gets data from server which is Web API based & so it gives data in json and/or XML format.

When app user logs in for the first time using his credentials(username,password), the response that comes from server is a success bit & a TOKEN, which should be used in successive URL requests.

I am using httpclient for sending requests

     using (HttpClient httpClient1 = new HttpClient())
                    {
                        string url = "http://example.com/abc/api/process1/GetLatestdata/10962f61-4865-4e7a-a121-3fdd968824b5?employeeid=6";

 //The string 10962f61-4865-4e7a-a121-3fdd968824b5 is the token sent by the server               

                        var response = await httpClient1.GetAsync(new Uri(url));

                        string content = await response.Content.ReadAsStringAsync();
                    }

Now the response that i get is with status code 401 "unauthorised". And the xml i get in response is "Unauthorised User".

Is there anything i need to change in appManifest??

Here is snapshot of app capabilities

I've checked this, but cant we use httpclient without credentials??

Community
  • 1
  • 1
Gk_999
  • 508
  • 8
  • 29

1 Answers1

1

Your Capabilities are enough. You don't even need Internet (Client) because it's included in Internet (Client & Server).

You do not have credentials for WinRT HttpClient, in your linked post they referr to System.Net.Http.HttpClientHandler.

Maybe you can use the HttpBaseProtocolFilter to add the credentials?

using (var httpFilter = new HttpBaseProtocolFilter())
{
    using (var httpClient = new HttpClient(httpFilter))
    {
        httpFilter.ServerCredential...
    }
}

I don't know your security mechanism, I'm using a HttpClient and my session-key is in a cookie. But I think your client code looks fine.

Dani
  • 971
  • 12
  • 31
  • Dani u r correct... my client code is fine... There was some problem at sever side in validating the request... Thanx – Gk_999 Nov 14 '14 at 09:15