I am trying to fetch an API REST response but the API’s URL has an “?” in the URL (see example below).
HttpWebRequest request = WebRequest.Create("http://api.mydomain.com/news/?tag=sports") as HttpWebRequest;
Is there a way to escape this?
I tried Uri.EscapeUriString and HttpUtility.HtmlEncode but that is not working either.
Any ideas?
You don’t need to escape anything. The
?is what separates the path portion of the url from the query string portion.http://api.mydomain.com/news/?tag=sportsis a perfectly valid url.Or maybe your API expects:
http://api.mydomain.com/news/sports? Difficult to say without knowing which API you are trying to consume.