簡體   English   中英

處理時間響應休息API

[英]process time response rest api

我想創建一個REST API客戶端,該客戶端可以處理從服務器獲得的任何響應的時間。

var client = new RestClient("http://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
request.AddUrlSegment("id", "123"); // replaces matching token in request.Resource

// easily add HTTP Headers
request.AddHeader("header", "value");

// add files to upload (works with compatible verbs)
request.AddFile(path);

// execute the request
IRestResponse response = client.Execute(request);

例如,我拿了示例代碼,在發送請求的同一行中得到了響應。

我應該運行另一個線程來計算時間,還是有另一種方法?

如果只需要代碼塊的經過時間,則可以使用System.Diagnostic.Stopwatch對其進行包裝來對其進行測量。 ElapsedMilliseconds為您提供毫秒數,也可以使用Elapsed屬性來獲取Timespan對象。 例如:

// Start a new stopwatch timer.
var timePerParse = Stopwatch.StartNew();

// code for operation you want to measure

timePerParse.Stop();
var elapsedMS = timePerParse.ElapsedMilliseconds;
Console.WriteLine(elapsedMS);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM