Reputation: 931
Today I tried to login on a page containing an auth form.
I'm using RestSharp on Windows Phone 7 and I tried almost everything but it didn't work.
In a browser on my desktop computer, when I use the login page (http://myanimelist.net/login.php) and enter my valid credentials, I'll be redirected to the panel page (http://myanimelist.net/panel.php)
On Windows Phone 7 (and 8) when I try to use RestSharp to auth myself, I'm redirected to the panel page but with the following error :
Error: You must first login to see this page.
In fact I'm not authenticated and I don't have the right to see the panel page.
I tried the same thing in a WPF application and there it worked.
In my WPF app I've the following code:
var client = new RestSharp.RestClient();
client.BaseUrl = "http://myanimelist.net/login.php";
client.Authenticator = new SimpleAuthenticator("username", "mylogin", "password", "mypassword");
client.CookieContainer = new CookieContainer();
var request = new RestRequest(Method.POST);
var response = client.Execute(request);
The property "response.Content" will contain the page with some informations and a Welcome message with my login. It means that I'm authenticated.
But...
With the following code in Windows Phone 7, the property "response.Content" will contain a page with some informations and the following message in it:
Error: You must first login to see this page
And here is the WP7 code used:
var client = new RestSharp.RestClient();
client.BaseUrl = "http://myanimelist.net/login.php";
client.Authenticator = new SimpleAuthenticator("username", "mylogin", "password", "mypassword");
client.CookieContainer = new CookieContainer();
var myRequest = new RestRequest(Method.POST);
client.ExecuteAsync(myRequest, response =>
{
var t = response.Content;
});
Did I miss something? Is there a difference between RestSharp on WP7 and a WPF app?
I used Fiddler to check what happens and I can see that the cookie is never set on WP7 (in the WPF app the cookie is set).
Edit:
I found something interesting, when I get the response, I can see in Fiddler that a cookie is set in the WPF app and in the WP7 app.
So I tried to add the cookie in my WP7 app before to make my request and it worked.
I added the value I could see in Fiddler but I can't find a way to retrieve these values with RestSharp.
Here is what I tried to add before to execute my request:
myRequest.AddParameter("A", "theFirstValue", ParameterType.Cookie);
myRequest.AddParameter("B", "theSecondValue", ParameterType.Cookie);
Upvotes: 0
Views: 490
Reputation: 931
In fact I found a way to do it.
In the response I've the cookie in the Header (Set-cookie). I extract the cookie from the header and add it to my next request which requires the cookie.
Upvotes: 1