我正在使用下面的代码来重用会话。
我会在grabUrl 响应cookie 上获得相同的会话ID 吗?
我如何知道两个请求是否使用相同的会话/cookie?
谢谢。
CookieContainer cookCon = new CookieContainer();
Httpwebrequest loginReq = (httpwebrequest) loginReq.create(loginurl);
loginReq.cookiecontainer = cookCon;
... All the response stuffs
Httpwebrequest grabReq = (httpwebrequest) grabReq.create(grabUrl);
grabUrl.cookiecontainer = cookCon
当我添加下面的代码来查看容器内容时,它显示有一个会话 id:
foreach (Cookie cook in cookieContainer.GetCookies(new Uri(loginurl)))
{
Console.WriteLine("Cookie_Get_Container:");
Console.WriteLine("====================================================");
Console.WriteLine("String: {0}", cook.ToString());
Console.WriteLine("====================================================");
}
所以我在登录响应中添加了 cookie:
cookieContainer.Add(new Uri(domainUrl), loginRes.Cookies);
当我尝试从 cookieContainer.grabRes.Cookies 获取时,我无法获取会话 ID。有什么建议吗?