我想用WebClient下载服务器上的文件,文件名是中文的,所以下载所需的url里就包括中文,比如http://......../画皮.mpeg
似乎需要做一些处理才能下载下来
如何实现下载url里包含中文的文件?

解决方案 »

  1.   

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      

  2.   

    URL编码问题像下面这样编码再解码试试
    str1 = Server.UrlEncode(Server.UrlEncode("下载的名称"))
    Response.Write(HttpUtility.UrlDeCode(Request["str1"],Encoding.GetEncoding("gb2312")); 
      

  3.   

    string str = Server.UrlEncode(Server.UrlEncode("下载URL")) 
    WebClient(str,path);
      

  4.   

    Server是指什么?服务器?
      

  5.   


    你引用System.web ,然后   str1 = Server.UrlEncode(Server.UrlEncode("下载的名称")) 
    Response.Write(HttpUtility.UrlDeCode(Request["str1"],Encoding.GetEncoding("gb2312")); 
      

  6.   

    Server.URLEncode("")
    Server.URLDecode("")
      

  7.   

    HttpUtility.UrlEncode(url);
    这些人真是的,cs结构下还老要别人用Server.UrlEncode。
      

  8.   

    HttpUtility能用于CS嘛?没有用过,呵呵
      

  9.   

    当然可以,它只是一个静态方法的集合而已。
    Utitlity嘛,不就是工具的意思?
      

  10.   

    private static string UrlDecodeStringFromStringInternal(string s, Encoding e)
    {
        int length = s.Length;
        UrlDecoder decoder = new UrlDecoder(length, e);
        for (int i = 0; i < length; i++)
        {
            char ch = s[i];
            if (ch == '+')
            {
                ch = ' ';
            }
            else if ((ch == '%') && (i < (length - 2)))
            {
                if ((s[i + 1] == 'u') && (i < (length - 5)))
                {
                    int num3 = HexToInt(s[i + 2]);
                    int num4 = HexToInt(s[i + 3]);
                    int num5 = HexToInt(s[i + 4]);
                    int num6 = HexToInt(s[i + 5]);
                    if (((num3 < 0) || (num4 < 0)) || ((num5 < 0) || (num6 < 0)))
                    {
                        goto Label_0106;
                    }
                    ch = (char) ((((num3 << 12) | (num4 << 8)) | (num5 << 4)) | num6);
                    i += 5;
                    decoder.AddChar(ch);
                    continue;
                }
                int num7 = HexToInt(s[i + 1]);
                int num8 = HexToInt(s[i + 2]);
                if ((num7 >= 0) && (num8 >= 0))
                {
                    byte b = (byte) ((num7 << 4) | num8);
                    i += 2;
                    decoder.AddByte(b);
                    continue;
                }
            }
        Label_0106:
            if ((ch & 0xff80) == 0)
            {
                decoder.AddByte((byte) ch);
            }
            else
            {
                decoder.AddChar(ch);
            }
        }
        return decoder.GetString();
    }这是HttpUtility.UrlEncode(url)最后调用的方法的源代码,呵呵
    就是一个对字符串串的处理而已
      

  11.   

    在Winform的项目中,似乎找不到HttpUtility这个类啊~
      

  12.   

    引用System.Web动态库,呵呵
      

  13.   

    当然找不到了,因为你还没引用 System.Web.dll 呢,先加进来吧.
      

  14.   

    不过告诉你,其他上面他们说的都不对,中文在DownloadData()时,都已被系统自动的转化了,根本不需要自己先转化一次.此问题我解决了,用winhttp或wininet都可以,唯独.net不行.
      

  15.   

    http://dotnet.aspx.cc/article/yuema9os-w1dn-4kis-8rie-s742llj91l6q/read.aspx
      

  16.   


                    Uri uri = new Uri("http://......../画皮.mpeg");
                    client.DownloadFile(uri,Application.StartupPath + "/画皮.mpeg");
      

  17.   

    using System.Net;
    WebClient client = new WebClient();
    Uri uri = new Uri("http://......../画皮.mpeg");
    client.DownloadFile(uri,Application.StartupPath + "/画皮.mpeg");
      

  18.   

    也就是说“画皮.mpeg”根本就不是这么显示在服务器上的,而是“(乱七八糟的字符).mpeg”