我使用WebClient连接到网络上的数据源,我需要提供用户名和密码。用户名可以包含正斜杠。但是,如果这在连接字符串中,则无法工作。
我的代码:
using (WebClient client = new WebClient)
{
data = client.DownloadString("https//myURL" + userID + password)对于“userID”(如"va2fsf“),这一切都很好,但对于包含正斜杠(如9k/vo1dsk )的va2fsf,则不起作用。
我该怎么处理?我试过使用%2F as in 9k%2Fvo1dsk,但这不起作用。
谢谢你的帮助!
发布于 2014-07-30 06:02:45
使用HttpUtility.UrlEncode。
data = client.DownloadString("https://myURL" +
HttpUtility.UrlEncode(userID) +
HttpUtility.UrlEncode(password))https://stackoverflow.com/questions/25029734
复制相似问题