I have to make a call to an API and the URL hasd this format: http://apiurl.com/method/parameter1/parameter2
Now, parameter2 may contain characters that could mess with the URL such as forward slashes, so I URL encode parameter2:
string parameter2 = HttpUtility.UrlEncode("string with a / in it");
System.Net.WebRequest request = System.Net.WebRequest.Create(String.Format("http://apiurl.com/method/{0}/{1}", parameter1, parameter2));
The problem is that if I inspect the URL of the request, parameter2 is NOT URL encoded and the call fails (unsurprisingly). However, when I inspect the value of parameter2 it is correctly URL encoded with the forward slash replaced with %2f
I am using .NET 3.5 so many of the usual workarounds don't apply (genericUriParserOptions for example is .NET 4 and above only)
Thanks