2016-04-25 123 views
0

我有一个Windows服务.Net客户端与PHP Web服务通信。基本的想法,.Net客户端发送信息到php写入数据库,这个过程花费1分钟,问题是,当它需要更多的时间,HttpResponseMessage来与BadGateway,有趣的是PHP实际上写所有的甚至在需要超过1分钟的时间内写入数据库。我尝试的HttpClient的超时设置为10分钟:.Net HttpResponse消息接收BadGateway超过1分钟时间

//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());     
     } 

但尽管如此,它失败比1分钟的反应越多,PHP的Web服务它想有10分钟的超时了。我登录了充分的反应和我得到了坏网关:

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 
} 

我的希望是,超时,此时的badgateway的原因,但它使没有区别。有人可以告诉我什么是badgateway的可能性,即使在php中的过程完成任务。提前致谢! PD:对不起,我的英语

回答

1

.NET端的超时不应该生成HTTP状态码。它应该引发一个单独的超时异常。如果你看到一个HTTP状态码,它必须来自服务器端。

您确定Web服务器本身(在PHP端)未配置脚本超时吗?

+0

....是第三方软,所以我不能100%肯定。但.Net本身无法做出一个坏的网关响应意味着没有可能与我有关? windows可以终止来自他的某个服务?或.net框架的http请求? – Aferrercrafter

+1

是的,由于多种原因,HTTP请求可能在客户端被终止,但我98%确定这不会作为HTTP状态代码显示。 HTTP状态代码应该只能从另一端的服务器通过。 –