I'm trying to access the REST-based API on Windows Phone using several different approaches, but I seem to be having problems attaching cookies to the request with all of them. I tried the approach WebClient(which now seems to have become SecurityCritical marked, so you can no longer inherit it and add code). I glanced briefly at HttpWebRequestwhich seemed bulky at best.
Now I use RestSharp, which seems decent to use, but I'm still having problems with my cookies not being added to the request when it is sent.
My code is as follows:
private RestClient client;
public ClassName() {
client = new RestClient();
client.BaseUrl = this.baseAddress.Scheme + "://" + baseAddress.DnsSafeHost;
}
public void GetAlbumList()
{
Debug.WriteLine("Init GetAlbumList()");
if (this.previousAuthToken == null || this.previousAuthToken.Length == 0)
{
throw new MissingAuthTokenException();
}
RestRequest request = new RestRequest(this.baseUrl, Method.GET);
Debug.WriteLine("Adding cookie [" + this.gallerySessionIdKey + "] = [" + this.sessionId + "]");
request.AddParameter(this.gallerySessionIdKey, this.sessionId, ParameterType.Cookie);
request.AddParameter("g2_controller", "remote:GalleryRemote", ParameterType.GetOrPost);
request.AddParameter("g2_form[cmd]", "fetch-albums-prune", ParameterType.GetOrPost);
request.AddParameter("g2_form[protocol_version]", "2.2", ParameterType.GetOrPost);
request.AddParameter("g2_authToken", this.previousAuthToken, ParameterType.GetOrPost);
request.AddHeader("cache-control", "no-cache");
client.ExecuteAsync(request, (response) =>
{
parseResponse(response);
});
}
- , cookie , :) RestSharp 101.3 .Net 4.