如何从URI获取zip文件 [英] How to get zip file from URI

查看:139
本文介绍了如何从URI获取zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows应用程序中,给URl并单击下载",然后"URL路径"将具有压缩文件",应在给定路径上下载

In windows application give URl and click download then The Url path will have Zipped File it should download on given path

private void button1_Click(object sender, EventArgs e)
{
   WebClient wc = new WebClient();
   wc.Proxy = null;
   wc.DownloadFile(downloadURL.Text, savePath.Text);
}

private void Form1_Load(object sender, EventArgs e)
{
   downloadURL.Text = @"http://www.codeproject.com/KB/IP/SimpleFTPDemo/SimpleFTP20_src.zip";
   savePath.Text = @"D:\1\2.zip";
}


这是我写的代码.在d中打开2.zip时:驱动它显示错误为


this is the code i wrote. while open 2.zip in d: drive it display error as

"Cannot open file: it does not appear to be a valid archive.<br />
If you downloaded this file, try downloading the file again."



我做错了什么?



what i did wrong?

推荐答案

如果这确实是CodeProject中的文件,则很可能您在尝试下载文件之前忘记了身份验证(登录).我建议您改用System.Net.HttpWebRequest类:
http://msdn.microsoft.com/en-us/library/system.net. httpwebrequest.aspx [ ^ ].

以下是几个问题,并附有解释方法的答案:
http://stackoverflow.com/questions/9841344/c-sharp-https-登录并下载文件 [ ^ ],
http://stackoverflow.com/questions/4699938/如何使用httpwebrequest-and-httpwebresponse-classcookies下载文件 [
If this is really a file from CodeProject, most likely you forgot to authenticate (login) before trying to download a file. I would advise that you use the class System.Net.HttpWebRequest instead:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].

Here are a couple of question with answers explaining how to do it:
http://stackoverflow.com/questions/9841344/c-sharp-https-login-and-download-file[^],
http://stackoverflow.com/questions/4699938/how-to-download-the-file-using-httpwebrequest-and-httpwebresponse-classcookies[^].

—SA


private void button1_Click(object sender, EventArgs e)
       {
  string url = downloadURL.Text;
           WebBrowser bweb = new WebBrowser();
           bweb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(bweb_DocumentCompleted);
           bweb.Navigate(new Uri(url));

       }

       void bweb_DocumentCompleted(object sender, webBrowserDocumentCompletedEventArgs e)
       {
           string url = downloadURL.Text;
           WebClient client = new WebClient();
           client.Credentials = new NetworkCredential("ravi", "ravi");
           client.BaseAddress = "http://www.codeproject.com";
           string FileName = url.Substring(url.LastIndexOf("/") + 1,
                           (url.Length - url.LastIndexOf("/") - 1));
           client.DownloadFile(url, savePath.Text + FileName);
       }


这篇关于如何从URI获取zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆