我沒有cookie的經驗,我試圖使用cookie(我從httpwebrequest
POST方法)訪問一個網站。在POST方法中,我完成了認證部分,最後我得到了cookie。我不知道如何使用這個cookie訪問一個網站,它類似於這個HttpWebRequest POST Method。使用來自httpwebrequest的cookie訪問網站windows phone
希望任何人都可以給我一些建議,指針或一些示例代碼。謝謝你的幫助。
這是我迄今爲止的代碼。
private void GetResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
using (IsolatedStorageFile isf =
IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = isf.OpenFile("CookieExCookies",
FileMode.OpenOrCreate, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(isfs))
{
foreach (Cookie cookieValue in response.Cookies)
{
sw.WriteLine(cookieValue.ToString());
}
sw.Close();
}
}
}
// Close the stream object
streamResponse.Close();
streamRead.Close();
response.Close();
//allDone.Set();
}
cookie存儲在文本框
private void ReadFromIsolatedStorage()
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs =
isf.OpenFile("CookieExCookies", FileMode.OpenOrCreate))
{
using (StreamReader sr = new StreamReader(isfs))
{
tbTesting.Text = sr.ReadToEnd();
sr.Close();
}
}
}
}
看。 – 2013-03-27 06:08:13