2016-04-25 120 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狀態代碼應該只能從另一端的服務器通過。 –