1
我想使用webbrowser class.i下载文件,我可以使用webbrowser进行登录和浏览。自动登录和文件下载
但该文件位于使用JavaScript的网站上。
我试图使用网页浏览器的cookies使用HttpWebRequest(fileurl)
获取文件。
登录后下载文件的代码如下。
string myUri = @"url_of_file";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
request.CookieContainer = new CookieContainer();
foreach (string cookie in webBrowser1.Document.Cookie.Split(';'))
{
string name = cookie.Split('=')[0];
string value = cookie.Substring(name.Length + 1);
string path1 = "/";
string domain = ".abcde.com"; //change to your domain name
request.CookieContainer.Add(new Cookie(name.Trim(), value.Trim(), path1, domain));
}
WebResponse res = request.GetResponse();
StreamReader sReader = new StreamReader(res.GetResponseStream());
StreamWriter sWriter = new StreamWriter(@"D:\file.csv");
while (sReader.Peek() >= 0)
sWriter.WriteLine(sReader.ReadLine());
sWriter.Close();
但是,响应流没有文件,而是在html body.as中有“url_of_file”。
<html><head></head>
<body onload="this.location.href='/Marketinfo/SubViewSubscriptionFile?product_code=DOL_INT&file_id=460916&subscription_id=318342&loadnow=true'">
</body></html>
请人所说的其实是错在这
谢谢,我可以下载文件。因为响应流有oonload.true.i只是加载&loadnow = true来回url.It工作。 – Radha