gpt4 book ai didi

c# - Mono Apache2 HttpWebRequest 崩溃并显示 "The request timed out"

转载 作者:太空狗 更新时间:2023-10-29 22:53:34 28 4
gpt4 key购买 nike

我在我的 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();

返回的错误是:

The request timed out

Description: HTTP 500. Error processing request.

Stack Trace:

System.Net.WebException: The request timed out at System.Net.HttpWebRequest.GetRequestStream () [0x0005f] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.Net/HttpWebRequest.cs:746 at TCShared.PxPay.SubmitXml (System.String InputXml) [0x00048] in /Users/liam/Projects/techcertain/techcertaincsharp/Components/TCShared/PaymentGateways/Client/PxPay.cs:85 at TCShared.PxPay.GenerateRequest (TCShared.RequestInput input) [0x00015] in /Users/liam/Projects/techcertain/techcertaincsharp/Components/TCShared/PaymentGateways/Client/PxPay.cs:69

在我的 Web.Config 中,我将以下内容作为请求超时:

<httpRuntime executionTimeout="43200" maxRequestLength="104856" requestValidationMode="2.0"  />

我已尝试更改 HttpWebRequest 的超时值,但它仍然超时。

发生这种情况的原因是什么,我该如何解决?

最佳答案

我设法找出我遇到这个问题的原因。它与 Apache 的使用完全无关。

我正在使用 Npgsql 访问 Postgresql 的数据库。 Npgsql 带有两个 dll(Npgsql.dll 和 Mono.Security.dll)。由于某些未知原因,Mono.Security.dll 导致 HttpWebRequest 在 Mono 上运行时超时。

无论如何,在 Mono 上运行时不需要 Mono.Security.dll,因为它已经包含在 Mono 框架中。因此,从我的 bin 目录中删除 Mono.Security dll 后,HttpWebRequest 就可以正常工作了。

这篇文章的全部功劳都在这里http://mono.1490590.n4.nabble.com/The-request-timed-out-at-HttpWebRequest-EndGetResponse-td2218213.html .

关于c# - Mono Apache2 HttpWebRequest 崩溃并显示 "The request timed out",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9952704/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com