处理时间响应休息 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 给你 ms 或者你可以使用 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);
我想创建 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 给你 ms 或者你可以使用 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);