Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uri constructor with dontEscape is obsolete, what is alternatieve?

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?

like image 837
Alnedru Avatar asked Dec 07 '12 07:12

Alnedru


People also ask

What is URI object in C#?

A URI is a compact representation of a resource available to your application on the intranet or internet. The Uri class defines the properties and methods for handling URIs, including parsing, comparing, and combining. The Uri class properties are read-only; to create a modifiable object, use the UriBuilder class.

What is a string URI?

A URI is a string containing characters that identify a physical or logical resource. URI follows syntax rules to ensure uniformity. Moreover, it also maintains extensibility via a hierarchical naming scheme. The full form of URI is Uniform Resource Identifier.


1 Answers

use this

Uri uri = new Uri(Uri.EscapeUriString(URL)); 
like image 129
Parimal Raj Avatar answered Sep 19 '22 17:09

Parimal Raj