Reputation: 21
I've searched for some time now and was not able to find a solution.
I'm currently developing an Windows Phone app (targeted for 7.1). In order to communicate with the Internet I'm using a NuGet-Package: Microsoft.Net.Http
The following code is used to communicate with a webserver:
CookieContainer container = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.UseCookies = true;
handler.CookieContainer = container;
HttpClient client = new HttpClient(handler);
Uri myUri = new Uri("http://my-server/ajax/login?action=login&name=user&password=passwd");
var task = client.GetStringAsync(myUri);
task.Wait();
String result = task.Result;
The result of this GET request is as expected. I've also checked the server side. The login process was successful and a valid JSESSIONID was returned to the client.
In order to verify my problem I've created a simple Console application with the exact same code as above (copy&pasted from my WP solution to a CL Solution (and the corresponding NuGetPackage stated above).
Now there is one BIG difference. I've set some breakpoints to view the variables:
On Windows Phone:
? container
{System.Net.CookieContainer}
Capacity: 300
Count: 0
MaxCookieSize: 4096
PerDomainCapacity: 20
And in my console application:
? container
{System.Net.CookieContainer}
Capacity: 300
Count: 3
MaxCookieSize: 4096
PerDomainCapacity: 20
I really don't know whats going on there... Someone said that it could be that the Cookies are marked as secure. I've checked this, and thats not the case. Due to the fact that the code works on a CLI application ensures me that the request is done correctly so far.
Has anyone some more information on what is going on there?
Upvotes: 1
Views: 767
Reputation: 21
I've just found my problem. Maybe somone else need this information, so i'm posting the solution.
My remote server was configured to sent this cookies as httpOnly cookies. Due to this fact my cookies are not visible in the CookieContainer object even if they are there.
The only strange thing is that if my code (or the PCL) is used in an console application the cookies are exposed to the CookieContainers public objects. In WinRT or Windows Phone apps they are not exposed. Seems that RT & WP are more closed down.
Changing my servers configuration to send the cookies as HttpOnly=false lets me see the cookies on the client side.
Upvotes: 1