How to quote a forward slash in a WebClient url?
-
21-12-2019 - |
Question
I am using WebClient to connect to a data source on the web and I need to provide a user name and password. The user name can contain a forward slash. However, if this is in the connect string it does not work.
My code:
using (WebClient client = new WebClient)
{
data = client.DownloadString("https//myURL" + userID + password)
This all works fine for a userID such as "va2fsf" but not for one containing a forward slash such as 9k/vo1dsk
.
How do I handle this? I tried using %2F as in 9k%2Fvo1dsk
but this doesn't work.
Thanks for any help!
Solution
data = client.DownloadString("https://myURL" +
HttpUtility.UrlEncode(userID) +
HttpUtility.UrlEncode(password))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow