我有一个Windows服务,我试图在服务器上运行。它只是将数据发布到php页面,并根据响应返回进一步的逻辑。对于网站(IIS),当打开匿名身份验证时,这在我的计算机上100%工作,在服务器上100%工作。
我想要完成的是在Windows身份验证开启的情况下运行该网站并让我的服务仍然有效...除非我尝试这个,否则我会收到一个很好的EventLog条目。
“System.IO.IOException:无法从传输中读取数据 连接:远程强制关闭现有连接 主机“
我在具有所有必需权限的帐户下运行该服务。所以我理解“CredentialCache.DefaultCredentials”应该使用此帐户进行身份验证(我没有收到401错误,但没有排除它)
下面是我的HttpPost代码,我从试图找到解决方案的其他帖子中设置了很多选项。
string postData = xml;
//--------------
HttpRequestCachePolicy policy = new HttpRequestCachePolicy MontgP02(HttpRequestCacheLevel.NoCacheNoStore);
HttpWebRequest.DefaultCachePolicy = policy;
byte[] buffer = Encoding.UTF8.GetBytes(postData);
//Initialisation
System.Net.ServicePointManager.Expect100Continue = false;
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
//Credentials
WebReq.UseDefaultCredentials = true;
WebReq.PreAuthenticate = true;
WebReq.Credentials = CredentialCache.DefaultCredentials;
//Request Settings
WebReq.ProtocolVersion = HttpVersion.Version11;
//WebReq.ServicePoint.ConnectionLimit = 1;
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
//The length of the buffer
WebReq.ContentLength = buffer.Length;
//Set timeout
WebReq.Timeout = 25000;
//Use Proxy or Not
if (useproxy == "ON")
{
WebProxy myProxy = new WebProxy();
// Create a new Uri object.
Uri newUri = new Uri(proxy);
// Associate the new Uri object to the myProxy object.
myProxy.Address = newUri;
WebReq.Proxy = myProxy;
}
try
{
//Send Data
using (Stream requestStream = WebReq.GetRequestStream())
{
// write to stream
//write, and close.
requestStream.Write(buffer, 0, buffer.Length);
}
}
catch (WebException ex) {
MessageLog("ERROR: Sending Data : " + ex.ToString() + ":", "ERROR");
}
//Get Response
try
{
using (System.Net.WebResponse response = WebReq.GetResponse())
{
Stream Answer = response.GetResponseStream();
// read from stream
StreamReader _Answer = new StreamReader(Answer);
PostResponse = _Answer.ReadToEnd();
}
}
catch (WebException ex)
{
MessageLog("ERROR: Receiving Response : " + ex.ToString() + ":" , "ERROR");
}
}
catch (WebException ex)
{
MessageLog("ERROR Posting " + ex.ToString() + ":" + PostResponse, "ERROR");
}
}
我从错误中了解到,在我完成请求之前,服务器正在切断连接。每次在服务器上都会发生这种情况,否定我会想到超时的想法。 看了看其他的四分之一,我不知所措,尝试了其他的变化等事实,它确实与认证工作正常关闭导致我认为它可能是IIS中的一个设置或其他其他认证路线。
欢迎任何见解