我也在寻找解决方案。也许是安全相关的:他们是否在 Intranet 安全区域中?http://www.codinghorror.com/blog/2005/04/aspnet-ntlm-authentication---is-it-worth-it.html
我在以下网址找到了这个:http ://bytes.com/topic/net/answers/544841-ntlm-authentication-how
这是一个开始,但他们也遇到了问题。
public string SendRequest()
// run the request and return a string response
{
string FinalResponse = "";
string Cookie = "";
NameValueCollection collHeader = new NameValueCollection();
HttpWebResponse webresponse;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.KeepAlive = true;
request.Timeout = 10000;
request.Method = "POST";
request.AllowAutoRedirect = false;
request.Proxy = WebProxy.GetDefaultProxy();
string addr = "http://" + ProxyServer + ":" + String.Format("{0:D}", ProxyPort);
Uri u = new Uri(addr);
CredentialCache wrCache = new CredentialCache();
wrCache.Add(u, "Negotiate", System.Net.CredentialCache.DefaultNetworkCredentials);
request.Proxy.Credentials = wrCache;
try
{
byte[] bytes = Encoding.ASCII.GetBytes(Request);
request.ContentLength = bytes.Length;
Stream oStreamOut = request.GetRequestStream();
oStreamOut.Write(bytes, 0, bytes.Length);
oStreamOut.Close();
webresponse = (HttpWebResponse)request.GetResponse();
if (null == webresponse)
{
FinalResponse = "No Response from " + URI;
}
else
{
Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader rdr = new StreamReader(webresponse.GetResponseStream(),enc);
FinalResponse = rdr.ReadToEnd();
}
}//End of Try Block
catch (WebException e)
{
// some kind of error..
if (407 == (int)e.Status)
{
}
throw CatchHttpExceptions(FinalResponse = e.Message);
}
catch (System.Exception e)
{
throw new Exception(FinalResponse = e.Message);
}
finally
{
// BaseHttp = null;
}
return FinalResponse;
} //End of SendRequestTo method