【发布时间】:2012-03-31 03:13:36
【问题描述】:
我在我的 ASP.Net 应用程序中使用支付网关 API。当使用 XSP 在 MonoDevelop 中进行测试时,应用程序可以工作。当我将其配置为使用 mod_mono 在 apache2 中运行时,代码会因超时错误而不断崩溃。
对于在 Apache 而不是 XSP 中托管会发生什么变化,我感到很困惑。无论如何下面是超时的代码:
private string SubmitXml(string InputXml)
{
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(_WebServiceUrl);
webReq.Method = "POST";
byte[] reqBytes;
reqBytes = System.Text.Encoding.UTF8.GetBytes(InputXml);
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = reqBytes.Length;
webReq.Timeout = 5000;
Stream requestStream = webReq.GetRequestStream();
requestStream.Write(reqBytes, 0, reqBytes.Length);
requestStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)webReq.GetResponse();
using (StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.ASCII))
{
return sr.ReadToEnd();
}
}
代码崩溃上线:Stream requestStream = webReq.GetRequestStream();
返回的错误是:
请求超时
说明:HTTP 500。处理请求时出错。
堆栈跟踪:
System.Net.WebException:请求超时 System.Net.HttpWebRequest.GetRequestStream () [0x0005f] 在 /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.Net/HttpWebRequest.cs:746 在 TCShared.PxPay.SubmitXml (System.String InputXml) [0x00048] 中 /Users/liam/Projects/techcertain/techcertaincsharp/Components/TCShared/PaymentGateways/Client/PxPay.cs:85 在 TCShared.PxPay.GenerateRequest(TCShared.RequestInput 输入) [0x00015] 在 /Users/liam/Projects/techcertain/techcertaincsharp/Components/TCShared/PaymentGateways/Client/PxPay.cs:69
在我的 Web.Config 中,请求超时如下:
<httpRuntime executionTimeout="43200" maxRequestLength="104856" requestValidationMode="2.0" />
我已尝试更改 HttpWebRequest 上的超时值,但仍然超时。
是什么导致了这种情况发生,我该如何解决?
【问题讨论】: