【发布时间】:2016-05-20 09:56:01
【问题描述】:
我想创建 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.Diagnostics.Stopwatch。
-
我想计算从发送请求到收到响应的时间,可以吗?