Hi, All
For Specific purpose, I write a WinForm program to display the HFS page through WebBrowser. When a user click a file, I intercept it, and get the URL of this file. I want to use WebClient to download it, and display it in my own Form. But there is an ERROR:
Intercept the file click:
private void web_browser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
String url_str = e.Url.ToString();
if (url_str.Substring(url_str.Length - 3).ToLower() == "pdf")
{
label1.Text = e.Url.ToString();
e.Cancel = true;
file_url = e.Url;
//DownloadFile(e.Url.ToString());
}
}Then I use WebClient to download it:
private void DownloadFile()
{
String local_file = System.IO.Path.GetTempPath() + "temp.pdf";
String temp_url;// = System.Web.HttpUtility.UrlEncode(file_url.ToString());
temp_url = @"http://eric.xin:%78%69%6E%36%31%35%36%34%36%36@192.168.1.209:9050/02%E6%8A%80%E6%9C%AF%E7%9F%A5%E8%AF%86%E5%BA%93/06%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%EF%BC%88%E6%B5%B7%E6%9E%97%EF%BC%89/How%20to%20fix%20LOST%20CARD.pdf";
WebClient client = new WebClient();
client.DownloadFile(temp_url, local_file);
}The URL contains user and password. I get an ERROR:
The remote server returned an error: (401) Unauthorized.How to fix it?