URI构造与dontEscape是过时的,什么是alternatieve? [英] Uri constructor with dontEscape is obsolete, what is alternatieve?

查看:407
本文介绍了URI构造与dontEscape是过时的,什么是alternatieve?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于传递一个URL来HttpWebRequest的不逃避,我搜索了论坛和互联网,但我没有为它找到一个很好的解决方案。

My question is regarding passing an URL to HttpWebRequest without escaping, I searched the forums and internet, but I didn't find a good solution for it.

我有下列网址:字符串URL = www.website.com/sub/redirec\t\bs\dd

所以,当我创建一个URI是这样的:

So when I create an uri like this:

Uri uri = new Uri(URL);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);

在这种情况下,一个get方法我将获得以下网址: WWW。 website.com/sub/redirect%5Ct%5Cbc%5Cdd

In this case on a get method I will get following URL:www.website.com/sub/redirect%5Ct%5Cbc%5Cdd

这标志\将被%5C所取代。 ?什么是我重要的不是发生

This sign "\" will be replaced by "%5C". What is crucial for me not to happen?

我能避免方式:

Uri uri = new Uri(URL, true); //bool dontEscape



不过,此构造是过时的。如何拥有不使用过时的同样的效果?

But this constructor is obsolete. How to have same effect without using obsolete?

推荐答案

使用

Uri uri = new Uri(Uri.EscapeUriString(URL)); 

这篇关于URI构造与dontEscape是过时的,什么是alternatieve?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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