Uri忽略特殊字符

时间:2013-11-26 08:03:40

标签: c# .net .net-4.5

我有一个代表网址的字符串,我想通过c#

下载内容

我的网址包含right to left markleft to right mark%E2%80%8F& %E2%80%8E。

当我在浏览器中粘贴网址时,我可以显示该文件。 当我在.net中使用代码时,我收到一个错误(因为.net忽略那些标记并且不会在请求中发送它们。

这是我得到的查询字符串

  

/ MBA%20%281%29 /%D7%90%D7%A1%D7%98%D7%A8%D7%98%D7%92%D7%99%D7%94%20%D7%A2 %D7%A1%D7%A7%D7%99%D7%AA%20%D7%AA%D7%97%D7%A8%D7%95%D7%AA%D7%99%D7%AA%20%28 %E2%80%8F%EF%BB%BF13015%E2%80%8E%29%E2%80%8F /%D7%93%D7%A4%D7%99%20%D7%A0%D7%95% D7%A1%D7%97%D7%90%D7%95%D7%AA%20%D7%9C%D7%9E%D7%91%D7%97%D7%9F /%D7%90%D7%A1 %D7%98%D7%A8%D7%98%D7%92%D7%99%D7%94%20%D7%93%D7%A3%20%D7%A0%D7%95%D7%A1%D7 %97%D7%90%D7%95%D7%AA-2%20%D7%A2%D7%9E-%203%20%D7%A2%D7%9E%D7%95%D7%93%D7% 95%D7%AA%20%D7%9C%D7%A8%D7%95%D7%97%D7%91.pdf

使用小提琴我可以.net发送

  

/ MBA%20(1)/%D7%90%D7%A1%D7%98%D7%A8%D7%98%D7%92%D7%99%D7%94%20%D7%A2% D7%A1%D7%A7%D7%99%D7%AA%20%D7%AA%D7%97%D7%A8%D7%95%D7%AA%D7%99%D7%AA%20(%EF %BB%BF13015)/%D7%93%D7%A4%D7%99%20%D7%A0%D7%95%D7%A1%D7%97%D7%90%D7%95%D7%AA%20 %D7%9C%D7%9E%D7%91%D7%97%D7%9F /%D7%90%D7%A1%D7%98%D7%A8%D7%98%D7%92%D7%99% D7%94%20%D7%93%D7%A3%20%D7%A0%D7%95%D7%A1%D7%97%D7%90%D7%95%D7%AA-2%20%D7% A2%D7%9E-%203%20%D7%A2%D7%9E%D7%95%D7%93%D7%95%D7%AA%20%D7%9C%D7%A8%D7%95%D7 %97%D7%91.pdf

你会注意到标记消失了。

任何想法如何解决?

这里有一些代码:      var s =“https://dl.dropboxusercontent.com/1/view/4fsaouo0ob52xkz/MBA%20%281%29/%D7%90%D7%A1%D7%98%D7%A8%D7%98%D7%92%D7%99%D7%94%20%D7%A2%D7%A1%D7%A7%D7%99%D7%AA%20%D7%AA%D7%97%D7%A8%D7%95%D7%AA%D7%99%D7%AA%20%28%E2%80%8F%EF%BB%BF13015%E2%80%8E%29%E2%80%8F/%D7%93%D7%A4%D7%99%20%D7%A0%D7%95%D7%A1%D7%97%D7%90%D7%95%D7%AA%20%D7%9C%D7%9E%D7%91%D7%97%D7%9F/%D7%90%D7%A1%D7%98%D7%A8%D7%98%D7%92%D7%99%D7%94%20%D7%93%D7%A3%20%D7%A0%D7%95%D7%A1%D7%97%D7%90%D7%95%D7%AA-2%20%D7%A2%D7%9E-%203%20%D7%A2%D7%9E%D7%95%D7%93%D7%95%D7%AA%20%D7%9C%D7%A8%D7%95%D7%97%D7%91.pdf”;

        using (HttpClient client = new HttpClient())
        {

            using (var sr = client.GetAsync(s).Result)
            {
                Console.WriteLine(sr.Headers);
            }

        }

我尝试手动创建uri并将其传递给httpClient - 保存结果。 sr - 得到403错误代码而不是200(我提供的链接无效但最终结果相同)。

1 个答案:

答案 0 :(得分:0)

试试这个:

 var uri = "https://dl.dropboxusercontent.com/1/view/4fsaouo0ob52xkz/MBA%20%281%29/%D7%90%D7%A1%D7%98%D7%A8%D7%98%D7%92%D7%99%D7%94%20%D7%A2%D7%A1%D7%A7%D7%99%D7%AA%20%D7%AA%D7%97%D7%A8%D7%95%D7%AA%D7%99%D7%AA%20%28%E2%80%8F%EF%BB%BF13015%E2%80%8E%29%E2%80%8F/%D7%93%D7%A4%D7%99%20%D7%A0%D7%95%D7%A1%D7%97%D7%90%D7%95%D7%AA%20%D7%9C%D7%9E%D7%91%D7%97%D7%9F/%D7%90%D7%A1%D7%98%D7%A8%D7%98%D7%92%D7%99%D7%94%20%D7%93%D7%A3%20%D7%A0%D7%95%D7%A1%D7%97%D7%90%D7%95%D7%AA-2%20%D7%A2%D7%9E-%203%20%D7%A2%D7%9E%D7%95%D7%93%D7%95%D7%AA%20%D7%9C%D7%A8%D7%95%D7%97%D7%91.pdf";


       string Url= System.Web.HttpUtility.UrlDecode(uri);
        //objDataToXml.GenerateXml();
       using (HttpClient client = new HttpClient())
       {

           using (var sr = client.GetAsync(Url).Result)
           {
               Console.WriteLine(sr.Headers);
           }

       }