Uri constructor with dontEscape is obsolete, what is alternatieve?

心不动则不痛 提交于 2019-12-06 17:48:00

问题


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.

I have following URL:string URL= www.website.com/sub/redirec\t\bs\dd

So when I create an uri like this:

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

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

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

I can avoid that by:

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

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


回答1:


use this

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


来源:https://stackoverflow.com/questions/13759034/uri-constructor-with-dontescape-is-obsolete-what-is-alternatieve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!