我没有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