【问题标题】:Mono Apache2 HttpWebRequest crashes with "The request timed out"Mono Apache2 HttpWebRequest 因“请求超时”而崩溃
【发布时间】: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 上的超时值,但仍然超时。

是什么导致了这种情况发生,我该如何解决?

【问题讨论】:

    标签: c# asp.net mono


    【解决方案1】:

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

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

    无论如何,在 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

    【讨论】:

    • 嘿,我遇到了和你一样的问题,只是删除 Mono.Security 并没有为我解决这个问题。这在两个不同的 linux 安装中是一致的,并且在 win 上也是一样的。您对我还应该尝试什么有什么想法吗?
    • 您好,您可以尝试使用其他版本的 Mono。我在我的 Mac 上使用 2.10.8 版本,并且 HttpWebRequest 正在工作。当我将 mono 升级到 2.10.9 版本时,HttpWebRequest 停止工作,所以我不得不降级回 2.10.8。
    • 删除 Mono.Security.dll 为我解决了这个问题,但您需要确保从您拥有源 dll 的任何文件夹(项目引用指向)以及您的 Bin/Debug| 中删除它。发布文件夹,因为它会从以前的版本复制到那里。
    • 谢谢你,这太棒了。删除了那个dll,它工作了。第一次尝试,dll在bin中重新生成。做了一个请求,它没有工作。一旦我删除了自动生成的 dll,它就可以工作了。现在只需要编写一个脚本来远程远程构建或更改一些配置,这样它就不会被生成。
    • 我发现这在 Mono 3.2.8 上也影响了我,删除 Mono.Security.dll 允许请求再次工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 2015-04-25
    • 1970-01-01
    • 2014-08-28
    • 2015-11-18
    相关资源
    最近更新 更多