我想创建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);
例如,我拿了示例代码,我在发送请求的同一行得到了响应。
我应该运行另一个线程来计算时间,还是有另一种方式?
答案 0 :(得分:0)
如果您只想要代码块的经过时间,可以使用System.Diagnostic.Stopwatch包装它来测量它。 ElapsedMilliseconds为您提供ms,或者您可以使用Elapsed属性来获取Timespan对象。例如:
var loadSound = function(url, callback) {
var loaded = function() {
callback(sound);
sound.removeEventListener('canplaythrough', loaded);
};
var sound = new Audio(url);
sound.addEventListener('canplaythrough', loaded)
sound.load();
};
window.onload = function() {
new Game("screen");
};
})();
//-->
</script>
</body>
</html>