如何用java计算网站的响应时间
how to calculate response time of a website in java
我正在尝试构建一个网站监控系统。我需要计算网站响应所需的时间或总加载时间。
如果您想计算http请求和响应之间的往返行程,可以使用apachehttp组件。这曾经被称为apachehttp客户端。
以下是我用于请求的一些示例代码。您可以在请求前后获取时间戳。
HttpClient httpclient = new DefaultHttpClient();
URIBuilder builder = new URIBuilder();
URI uri = null;
HttpEntity entity = null;
InputStream inputStream = null;
JSONObject jsonObject = null;
URL url = this.getClass().getClassLoader().getResource("json" + File.separator + "newInstall.json");
try {
String json = FileUtil.readFile(url.getPath());
builder.setScheme("http").setHost(host).setPort(8080).setPath(basePath + authResource)
.setParameter("sig", "sig").setParameter("params", json);
uri = builder.build();
log.info("uri: {}", uri);
HttpGet httpget = new HttpGet(uri);
HttpResponse response = httpclient.execute(httpget);
entity = response.getEntity();
if (entity != null) {
inputStream = entity.getContent();
String jsonString = IOUtils.toString(inputStream, "UTF-8");
jsonObject = new JSONObject(jsonString);
log.info("auth response: {}", jsonString);
}
} catch (Exception e) {
log.error("error", e);
}finally {
if(inputStream != null) {
try {
inputStream.close();
}catch(Exception ex) {
log.error("error closing input stream", ex);
}
}
}
相关文章:
- 使无响应的网站响应尽可能容易
- 使用skel框架构建的响应式网站只有在使用漂亮的URL时才能应用css
- 如何用java计算网站的响应时间
- 最大限度地减少Google AdWords Script的响应时间
- 使用JavaScript,PHP Ajax和Zend框架创建响应式网站的标准方法是什么?
- 如何修复移动响应式网站上的粘性滚动
- 如何使用javascript记录两次按钮按下之间的响应时间(以秒为单位)
- 如何测量 http.NodeJS 中的 ClientRequest 响应时间
- 用不同的方式创建响应式网站
- Web API处于非活动状态5分钟后响应时间过长
- 横向滚动响应式网站
- 如何创建响应式网站设计
- 如何在响应式网站中正确布局网格项目
- REST API测量服务器端响应时间(性能)
- 使用Heroku进行套接字轮询时响应时间长
- 问题与js不工作在响应式网站
- Microsoft Face Api响应时间
- 更改offline.js中允许的服务器响应时间
- 如何在redux框架中使用Action和Reducer记录响应时间
- Revolution Sliders字体像素化,在响应式网站的iPhone6中看起来不太好