我有一个Windows服务.Net客户端与PHP Web服务通信。基本的想法,.Net客户端发送信息到php写入数据库,这个过程需要花费1分钟,问题是,当需要更多时,HttpResponseMessage自带BadGateway,有趣的是php实际上写了所有有的即使花费超过1分钟也要在数据库中写入。我尝试将HttpClient的TimeOut设置为10分钟:
//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:抱歉我的英文
答案 0 :(得分:1)
.NET端的超时不应该生成HTTP状态代码。它应该抛出一个单独的超时异常。如果您看到HTTP状态代码,则必须来自服务器端。
您确定Web服务器本身(在PHP端)没有配置脚本超时吗?