Windows PhoneでRESTベースのAPIにアクセスしようとしましたが、すべてのリクエストでクッキーを添付して問題が発生しているようです。私はWebClient
アプローチを試しました(今はSecurityCriticalとマークされているように見えるので、もうそれを継承してコードを追加することはできません)。私は簡潔にHttpWebRequest
を見ましたが、これは面倒なようでした。RestSharpでクッキーを送信することができません
私はRestSharpを使用していますが、まあまあですが、送信時にリクエストに追加されていないCookieにはまだ問題があります。
私のコードは次のとおりです。
// ... some additional support vars ...
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 prints the correct key and value, but it doesnt seem to be included
// when I run the request
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);
// Tried adding a no-cache header in case there was some funky caching going on
request.AddHeader("cache-control", "no-cache");
client.ExecuteAsync(request, (response) =>
{
parseResponse(response);
});
}
誰でもクッキーがサーバーに送信されていない理由として任意のヒントを持っている場合は、私はRestSharp 101.3および.NETを使用しています:)お知らせください4.
どのようにクッキーがリクエストに含まれていないと判断していますか? –
私はエミュレータのプロキシとしてFiddlerを実行していましたが、確かに$ _COOKIEを出力したPHPファイルを指してみました。 – NiteLite
他の誰かが同じ問題を抱えている場合に備えて、私はこの繁栄のためにこのリンクを残します。 RestSharpコードの問題です:http://groups.google.com/group/restsharp/browse_thread/thread/d93f73e9e300ba43 – NiteLite