我没有使用 cookie 的经验,我尝试使用 cookie(我从httpwebrequest
POST方法获得)来访问网站。在POST方法中,我完成了身份验证部分,最后得到了 cookie。我不知道如何使用这个 cookie 访问一个网站,它类似于这个HttpWebRequest POST Method。
希望任何人都可以给我一些建议,指针或一些示例代码。谢谢你的帮助。
这是我到目前为止完成的代码。
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();
}
TextBox 中的 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();
}
}
}
}