[英]Call to GetResponse() is throwing (500) Internal Server Error
What is causing this exception to be thrown, and how could it be remedied 是什么导致引发此异常,以及如何解决该异常
I am making an API Post to server, passing a serialized XML file, and I expect one for the return call. 我正在向服务器进行API发布,传递了序列化的XML文件,并且我希望返回调用一个文件。
Instead my code is throwing a 500 Internal Server Error at the GetResponse() call. 相反,我的代码在GetResponse()调用中引发了500 Internal Server Error。
I have checked the syntax of my file, and it is correct. 我已经检查了文件的语法,它是正确的。 I also know that my logic works as I have used it for other calls.
我也知道我的逻辑工作正常,就像我将其用于其他呼叫一样。
try
{
wWebRequest = (HttpWebRequest)WebRequest.Create(strWebAddressAuthentication);
wWebRequest.CookieContainer = new CookieContainer();
wWebRequest.Method = sHTTPTransMethod;
wWebRequest.ServicePoint.Expect100Continue = false;
wWebRequest.UserAgent = sUserAgent;
wWebRequest.ContentType = srequestContentType;
FileInfo fInfo = new FileInfo(filename);
long numBytes = fInfo.Length;
double dLen = Convert.ToDouble(fInfo.Length / 1000000);
if (dLen < 100)
{
fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
br = new BinaryReader(fStream);
data = br.ReadBytes((int)numBytes);
br.Close();
wWebRequest.ContentLength = data.Length;
dataStream = wWebRequest.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
response = (HttpWebResponse)wWebRequest.GetResponse();
foreach (Cookie cook in response.Cookies)
{
myCookieContainer.Add(cook);
}
txtXmlReturned.Text = (((HttpWebResponse)response).StatusDescription);
sServerResponse = txtXmlReturned.Text + Environment.NewLine;
dataStream = response.GetResponseStream();
reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
txtXmlReturned.Text = txtXmlReturned.Text + responseFromServer + Environment.NewLine;
reader.Close();
response.Close();
fStream.Close();
fStream.Dispose();
// -----------------------------------------------------------
}
else
{
MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Upload Error");
}
}
A 500 Internal Server Error means there's a problem on the server side. 500 Internal Server Error表示服务器端有问题。 You're writing for the client.
您正在为客户写作。 See what happens if you go to the url you're using in a browser.
查看在浏览器中使用的URL会发生什么。
For us, one of our apps stopped working and responded with a 500 code. 对于我们来说,我们的一个应用程序停止了工作,并返回了500个代码。 Turned out the application pool crapped out.
原来应用程序池被淘汰了。 Restarting the site in question cleared it up.
重新启动有问题的站点将其清除。 Of course, there could be some other underlying problem, but the app has been running for years and this is only the second time we've encountered a 500 with it.
当然,可能还有其他一些潜在的问题,但是该应用程序已经运行了多年,这只是我们第二次遇到500。 Nothing was logged by our app either.
我们的应用也未记录任何内容。
Give IIS a check, assuming it is IIS and you have access to the server, and see if anything has gone astray there. 假设它是IIS并且您可以访问服务器,请给IIS检查,看看那里是否有任何误入歧途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.