2014-06-25 32 views
0

我想弄清楚如何清除Windows Phone 8 cordova插件中的cookie。如何清除Windows Phone 8 cordova插件中的cookie?

我一直在玩的意見在這裏http://cloudstore.blogspot.in/2010/09/clearing-cookies-on-windows-phone-7-or.html這裏http://developer.nokia.com/community/wiki/Integrate_Facebook_to_Your_Windows_Phone_Application

這基本上是你要麼在web瀏覽器實例,並使用一個方便的方法,像這樣:

await browserInstance.ClearCookiesAsync(); 

或你從請求中的cookie,並丟棄/到期他們,就像這樣:

HttpWebRequest _webRequest; 
Uri uri = new Uri("https://blah.com"); 
CookieContainer _cookieContainer = new CookieContainer(); 
_webRequest = (HttpWebRequest)HttpWebRequest.Create(uri); 
_webRequest.CookieContainer = this._cookieContainer; 
var cookies = this._cookieContainer.GetCookies(uri); 
foreach (Cookie cookie in cookies) 
{ 
    cookie.Discard = true; 
    cookie.Expired = true; 
} 

我的問題是雙重的:

1)我不知道如何讓科爾多瓦瀏覽器實例,以嘗試調用ClearCookiesAsync()方法

2)我不使用HttpWebRequest對象,因爲我需要訪問設置一些報頭信息,我使用了HTTPClient對象和HTTPRequestMessage即:

HttpClient client = new HttpClient(); 
client.BaseAddress = new Uri("https://blah.com"); 
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html")); 
client.DefaultRequestHeaders.Add("Some custom stuff","More custom stuff"); 
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get,"/something/hello.php"); 
HttpResponseMessage response = await client.SendAsync(req); 
response.EnsureSuccessStatusCode(); 
string responseBody = string.Empty; 
responseBody = await response.Content.ReadAsStringAsync(); 
Debug.WriteLine(responseBody); 

所以基本上,如果我能想出如何從科爾多瓦瀏覽器的一個實例,而一個插件中,或者,清除餅乾從HTTPClient這將是好的。

編輯:有趣的... How can I get HttpOnly cookies in Windows Phone 8?

顯然,你可以得到通過HttpClientHandler訪問餅乾,所以我的代碼開始以上會是這樣......

HttpClientHandler handler = new HttpClientHandler(); 
handler.CookieContainer = new CookieContainer(); 
HttpClient client = new HttpClient(handler); 

...但創建一個新的Cookie容器似乎沒有清除cookie?

這也看起來有趣:Struggling trying to get cookie out of response with HttpClient in .net 4.5

我打了上面的鏈接,並且確實檢索來自HttpResponseMessage而是試圖使用無效和cookie.Discard cookie.Expired不起作用這些Cookie餅乾。

看起來好像答案是你必須讓科爾多瓦瀏覽器實例放棄cookies,上面只會讓你玩個人反應中的cookie,看起來是隻讀方式:(

類似/重複的問題:

Access to cookies or WebBroswer class from phonegap plugin running windows phone ClearCookiesAsync() on Cordova

回答

0

我發現這樣做是使用基於服務器的更簡單的方式「退出」鏈接,將設置cookie的失效你的cookie,通過設置相同在過期的cookie過去的。

基本上,雖然android和ios可以做我想做的事情,但是看起來你不能使用windows phone API輕鬆做到這一點,因爲我發現API「is」在那裏,但很難通過cordova進行訪問插件出於在問題中解釋的原因

相關問題