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??

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Dani u r correct... my client code is fine... There was some problem at sever side in validating the request... Thanx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.