某网页,我不想做登录界面,直接使用域的帐号密码来访问。如果网站设置成Window身份验证,单独的页面都没问题,而是通过使用HttpWebRequest对象访问,会导致错误:
远程服务器返回错误:(401)未经授权。
后来找到处理代码,处理前代码如下:
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(sURL + "ShipWorkFlow.ashx");
hwr.Method = "GET";
hwr.SendChunked = false;
处理后代码如下:
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(sURL + "ShipWorkFlow.ashx");
hwr.PreAuthenticate = true;
NetworkCredential myCred = new NetworkCredential("user", "1234", "abc");
hwr.Credentials = myCred;
hwr.Method = "GET";
hwr.SendChunked = false;