繁体   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