Rocho.J

人脑是不可靠的, 随时记录感悟并且经常重复!

 

HttpWebRequest设置用户名密码后, 依然返回401未授权错误

 

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();

 

posted on 2011-12-31 19:54  RJ  阅读(...)  评论(... 编辑 收藏

导航

统计