2011-08-19 61 views
1

我目前使用HttpGet(apache)方法向Web服務發出請求。 當我打電話這是給我這個錯誤的服務器:如何將日期標題添加到httpGet

「請求時間和服務器時間之間的差異過大」 後來我才知道,服務器需要在格林尼治標準時間的請求,以便我確實添加了一個頭(addHeader)來做同樣的事情。但我仍然有同樣的問題。

有什麼想法/想法?

一些代碼:

final String url = "ip address"; 
    final HttpGet request = new HttpGet(url); 
    final ArrayList<NameValuePair> nameValues = new ArrayList<NameValuePair>(); 
    nameValues.add(new BasicNameValuePair("Authorization", "XXXX")); 
    nameValues.add(new BasicNameValuePair("date", "Fri, 19 Aug 2011 22:39:13 GMT")); 
    for (final NameValuePair h : nameValues) 
    { 
     request.addHeader(h.getName(), h.getValue()); 
    } 
    final HttpClient client = new DefaultHttpClient(); 
    HttpResponse httpResponse; 
    try 
    { 
     httpResponse = client.execute(request); 
     responseCode = httpResponse.getStatusLine().getStatusCode(); 
     message = httpResponse.getStatusLine().getReasonPhrase(); 
     final HttpEntity entity = httpResponse.getEntity(); 

     if (entity != null) 
     { 
      final InputStream instream = entity.getContent(); 
      response = convertStreamToString(instream); 
      instream.close(); 
     } 
    } 
    catch (final Exception e) 
    { 
    } 
+1

顯示一些代碼 - –

+0

您可以使用像「webscarab」這樣的「調試代理」來驗證標題並將我們的客戶端 - 服務器交互日誌轉儲給我們嗎? https://www.owasp.org/index.php/OWASP_WebScarab_NG_Project – andcoz

+0

我從來沒有這樣做......但使用鏈接,我會得到客戶端 - 服務器交互的轉儲。 – Rishi

回答

0

我能夠把它解決。
我發現當我使用CST進行呼叫時,服務器已經設置爲GMT。