以下代码是webservice中的post方法。 问题: NTML身份验证在.net framework 4.5中运行良好,但我想在.net framework 3.5中运行代码,使项目与windows xp兼容。
错误:401未经授权
try
{
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object sender2, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
};
WebRequest request = WebRequest.Create("http://192.168.100.254"+urldata);
request.Method = "POST";
//NTML authentication
CredentialCache cc = new CredentialCache();
cc.Add(
new Uri("http://192.168.100.254"),
"NTLM",
new NetworkCredential("admin", "mnjkl"));
request.Credentials = cc;
byte[] byteArray = Encoding.UTF8.GetBytes(data);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
return responseFromServer;
}
catch (Exception Ex)
{
throw Ex;
}
请任何知道.net3.5中NTLM身份验证的人帮助我。感谢。
答案 0 :(得分:0)
我有同样的问题。 我能够通过改变突出显示的本地组策略来解决它们 您需要做的就是右键单击该策略并单击属性,您需要取消选中使用128位ssl Screenshot of the settings in local group policy