2013-04-09 55 views
-1

我有一個問題,它讓我瘋狂。在我的應用程序中,我需要獲取本地郵票的價值,服務器請求的延遲,服務器戳記以及對應用程序的響應延遲。如何獲得延遲

的值只有我能得到的是當地的郵票,該郵票服務器和一個完整的週期(請求+響應)的時間。那麼如何獲得請求延遲以及響應延遲。

+0

你在做用PHP請求? – Dale 2013-04-09 06:57:32

+0

沒有,只是響應 – 2013-04-09 07:53:05

回答

0

如果你正在做用PHP請求,你可以使用的東西沿着這些路線:

<?php 
    // start a timer 
    $start_time = microtime(true); 
    // do some network stuff 
    // example is read google.com 
    $buffer = file_get_contents('http://www.google.com'); 
    // echo the current time minus the start time 
    echo number_format(microtime(true) - $start_time, 5) . ' seconds'; 
+0

這不正是我需要的,但你的microtime中()和number_format()是真的要幫我謝謝你。 – 2013-04-09 09:53:04

+0

嗯,我很高興以某種方式:)好運來幫助 – Dale 2013-04-09 09:55:46

0
long sendtime,latncyTime; 
HttpPost httppost = new HttpPost("http://your-url.com"); 

      List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(
        2); 
      nameValuePairs.add(new BasicNameValuePair("username", 
        "ARUN")); 
      nameValuePairs.add(new BasicNameValuePair("password", 
        "****")); 
      try { 
       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

sendtime=System.currentTimeMillis(); 
       HttpResponse response = httpclient.execute(httppost); 
       if (response.getStatusLine().getStatusCode() == 200) { 
latncyTime=System..currentTimeMillis()-sendtime; 



       } 

      } catch (Exception e) { 
       // TODO: handle exception 
       e.printStackTrace(); 

      } 
+0

我actualy已做部分(請求+響應) – 2013-04-09 09:24:54

+0

然後你會得到延遲 – 2013-04-09 09:30:14

+0

對我來說,等待是時間的請求將達到目的地。我錯了嗎 ? – 2013-04-09 11:23:58