无法找到将我从cookiemanager中获取的cookie添加到我的HttpWebRequest中的方法..我发送一个SOAP(你必须连接的地方)
HttpWebRequest webRequest = CreateWebRequest(_url, _action);
webRequest.CookieContainer = new CookieContainer();
CookieManager cookieManager = CookieManager.Instance;
CookieCollection cookieCollection = new CookieCollection();
string cookiestring = cookieManager.GetCookie(_url);
foreach (var pair in cookiestring.Split(' '))
{
string[] cookies = pair.Split('=');
cookieCollection.Add(new Cookie(cookies[0], cookies[1]));
Console.WriteLine("========NEW COOKIES======");
Console.WriteLine(cookies[0] + " " + cookies[1]);
}
try
{
webRequest.CookieContainer.Add(cookieCollection);
}
catch
{
for(var i = 0; i<100; i++) Console.WriteLine("I'm a failure because I can't even add a stupid cookie");
}
我对此的回应是:
========新COOKIES ======
.ASPXAUTH LONGASSCODE
意思是他有数据cookie,但是当我将cookiecollection添加到webrequest的cookiecontainer时它就失败了