尝试使用摘要式身份验证与Web服务器(Apache 2.2.17)通信并使用POST方法发送数据时遇到问题:它始终返回401错误。但是,如果我们不发布数据,或者当Fiddler正在运行(即使发布数据时),它也会运行良好......您是否了解可能导致问题的原因?奇怪的HTTP身份验证问题
public void DoRequest(string v_strURL, XmlDocument v_objXMLDoc)
{
var credentialCache = new CredentialCache();
credentialCache.Add(new Uri("http://" + ServerIP + "/"), "Digest", new NetworkCredential("admin", "test", "realm"));
String RequestContent = "request=" + v_objXMLDoc.InnerXml.Replace(' ', '+');
Uri Url = new Uri(v_strURL);
HttpWebRequest objHttpWebRequest;
HttpWebResponse objHttpWebResponse = null;
Stream objRequestStream = null;
byte[] bytes = new byte[0];
bytes = System.Text.Encoding.UTF8.GetBytes(RequestContent);
objHttpWebRequest = (HttpWebRequest)WebRequest.Create(v_strURL);
objHttpWebRequest.UserAgent = "MySampleCode";
objHttpWebRequest.Credentials = credentialCache;
objHttpWebRequest.Method = "POST";
objHttpWebRequest.ContentLength = bytes.Length;
objHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";
objHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
objRequestStream = objHttpWebRequest.GetRequestStream();
objRequestStream.Write(bytes, 0, bytes.Length);
objRequestStream.Close();
objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
}
请出示一些源代码和 – Yahia
你需要显示源代码比较有什么越过线(有和没有小提琴手),例如使用Wireshark ...我写了大量的C#代码,它们使用HTTP发布数据并摘要身份验证,这些身份验证在生产环境中使用并且没有问题。因此,无论您的代码是否存在一些错误,或者存在服务器配置问题,没有示例代码/更多细节,都无法分辨! – RobV
我会尽快发布源代码! – JoRoy