不支持 URI 格式:在 C# 中从 Web 客户端下载远程文件时 [英] URI Formats not Supported: while downloading remote file from Web client in c#

查看:41
本文介绍了不支持 URI 格式:在 C# 中从 Web 客户端下载远程文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从服务器下载文件.将链接传递给下载 File 时,它​​抛出错误

I'm trying to download a file from the server . While passing a link to the download File , it is throwing an error

**URI 格式不受支持 ** 并指向链接"-字符串包含服务器文件地址

**URI Formats are not supported ** and pointing at "link "- string contains server file address

string link =
    http:\\www.nse-india.com\DERIVATIVES\2012\AUG\fo22AUG2012bhav.csv.zip

          WebClient wc = new WebClient();

        var ua = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
        wc.Headers.Add(HttpRequestHeader.UserAgent, ua);
        wc.Headers["Accept"] = "/";

下载代码是这样的

    try
  {
   wc.DownloadFile(@link, "H:\\ZipTest\\ZipText\\nt.zip"); // Here Showing error
  _status = true;
   fileCount++;

  } catch (Exception ex)

  {
    MessageBox.Show(ex.Message);
    _status = false;
    }

如果我在网络浏览器中使用了相同的地址,它可以正确下载,或者如果替换了一些其他文件,那么我也可以从相同的代码下载仅用于我遇到问题的这个特定文件,知道吗??

if i used the same address in the web browser it downloading properly or if a replace some other files then also i can download from the same code only for this particular file i am facing problem , any idea??

推荐答案

Url 需要一点修改

Url need little modification

改变

string link =
    "http:\www.nse-india.com\DERIVATIVES\2012\AUG\fo22AUG2012bhav.csv.zip"

string link =
    "http://www.nse-india.com/DERIVATIVES/2012/AUG/fo22AUG2012bhav.csv.zip"

这篇关于不支持 URI 格式:在 C# 中从 Web 客户端下载远程文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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