|
如何根据网址获取请求时的coookie。 public static Stream GetModelStream(string strUrl, string server)//, string proxy, bool isProxy)
{
System.IO.Stream resStream = null;
string cookie;
try
{
HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(strUrl);
httpRequest.Timeout = 2000;
httpRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
httpRequest.Referer = server;
httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)";
HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
cookie = httpResponse.Headers.Get("Set-Cookie");
myCookie = new CookieContainer();
myCookie.SetCookies(new Uri(server), cookie);
resStream = httpResponse.GetResponseStream();
}
catch { }
return resStream;
}
这网上找的一段,
|
|