HttpWebRequest设置用户名密码后, 依然返回401未授权错误, 手动在请求中添加授权标识头["Authorization"],
但是, base64一下用户名和密码, 安全问题??? 内网环境, 这位提待解决!
View Code
string _svnDBPath = "http://192.168.199.66/svn/FAE/";
if (!db.StartsWith(_svnDBPath))
throw new Exception("");
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(db.Trim());
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(_svnPath), "Basic", new NetworkCredential(_svnUName, _svnPwd));
myRequest.Credentials = myCache;
myRequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(_svnUName + ":" + _svnPwd));
myRequest.GetResponse();