asp.net 设置全局代理和添加cookie实现文件下载
string webporxy = System.Configuration.ConfigurationManager.AppSettings["WebPoxy"].ToString();// 获取代理:127.0.0.1:800 if (webporxy != string.Empty) System.Net.WebRequest.DefaultWebProxy = new WebProxy(webporxy); Cookie cok = new Cookie("pausername", "ServUcn"); Cookie cok1 = new Cookie("pauserid", "6172260"); Cookie cok2 = new Cookie("papasswordhash", "507277cf24a404d4911efdf12a59ae5e"); HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.ucasp.net"); req.CookieContainer = new CookieContainer(); req.CookieContainer.Add(new Uri("http://www.ucasp.net"), cok); req.CookieContainer.Add(new Uri("http://www.ucasp.net"), cok1); req.CookieContainer.Add(new Uri("http://www.ucasp.net"), cok2); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); System.IO.Stream resData = res.GetResponseStream() ; System.IO.StreamReader reader = new System.IO.StreamReader(resData, System.Text.Encoding.GetEncoding("gb2312")); string content = reader.ReadToEnd(); Response.Write(content)
发布于 posted on 2006年12月3日 20:16   由 祥子
:: 

Powered by Community Server Powered by CnForums.Net