dougua4836 2016-04-25 15:08
浏览 87
已采纳

.Net HttpResponseMessage接收BadGateway时需要1分钟以上

I have a windows service .Net client comunicating with a PHP web service. The basic idea, the .Net client send information to php to write in data base, this process take araund 1min, the problem is that, when it takes more, the HttpResponseMessage comes with BadGateway, the funny thing is php actually write all that has to write in the database even when it takes more than 1min. I try to set the TimeOut of HttpClient to 10min:

//code for the stuff making
Logger.WriteLog("Sending Stuff");
using (var client = new HttpClient())
        {
            client.Timeout = new TimeSpan(0,10,0);
            httpResponseMessage = client.PostAsync(url, content).Result;
            Logger.WriteLog(httpResponseMessage.StatusCode.ToString());
            Logger.WriteLog(httpResponseMessage.ToString());                
        }

But still, it fail with more than 1min response, the php web service it suppose to have a timeout of 10min too. I log the full response and i got the bad Gateway:

2016-04-25 11:12:24,045 INFO  - *Sending Stuff
2016-04-25 11:13:23,413 INFO  - OK
2016-04-25 11:13:23,414 INFO  - StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Pragma: no-cache
  Connection: close
  Cache-Control: no-store, must-revalidate, no-cache, post-check=0, pre-check=0
  Date: Mon, 25 Apr 2016 14:12:37 GMT
  Set-Cookie: PHPSESSID=lbhsue3pstc8smqihkoe0nouj1; path=/
  Server: Apache/2.2.15
  Server: (CentOS)
  X-Powered-By: PHP/5.6.19
  Content-Length: 52
  Content-Type: application/json; charset=UTF8
  Expires: Thu, 19 Nov 1981 08:52:00 GMT
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
2016-04-25 11:14:42,931 INFO  - *Sending Stuff
2016-04-25 11:15:44,273 INFO  - BadGateway
2016-04-25 11:15:44,274 INFO  - StatusCode: 502, ReasonPhrase: 'Proxy Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Connection: close
  Date: Mon, 25 Apr 2016 14:14:43 GMT
  Content-Length: 499
  Content-Type: text/html; charset=iso-8859-1
}
//------------------------------------------------------------------------------------------------------------------------------------------------
2016-04-25 11:25:28,471 INFO  - *Sending Stuff
2016-04-25 11:26:27,495 INFO  - OK
2016-04-25 11:26:27,497 INFO  - StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
 Pragma: no-cache
 Connection: close
 Cache-Control: no-store, must-revalidate, no-cache, post-check=0, pre-check=0
 Date: Mon, 25 Apr 2016 14:25:41 GMT
 Set-Cookie: PHPSESSID=ja6f30mqlnhtdl8p44hddr43c3; path=/
 Server: Apache/2.2.15
 Server: (CentOS)
 X-Powered-By: PHP/5.6.19
 Content-Length: 52
 Content-Type: application/json; charset=UTF8
 Expires: Thu, 19 Nov 1981 08:52:00 GMT
}

My hope was that, timeout where the reason of the badgateway but it make not difference. Can someone tell me what are the possibilities of the badgateway, even when the process in php finish the task. Thanks in advance! PD:Sorry for my english

  • 写回答

1条回答 默认 最新

  • dongzi5673 2016-04-25 15:14
    关注

    A timeout on the .NET end shouldn't generate an HTTP status code. It should throw a separate timeout exception. If you see an HTTP status code, that has to come from the server side.

    Are you sure the web server itself (on the PHP end) isn't configured with a timeout for scripts?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端