我一直在使用 volley 对服务器进行休息调用。我正在尝试将每个请求的响应时间发送到 Google analytic 以分析服务器延迟,在 volley jsonobject 请求中有什么方法可以找到每个请求的响应时间。 如果 volley 不提供此功能,我该如何计算每个请求的响应时间?。
最佳答案
您需要自己计算。这是查看响应到达所需时间的快速方法:
private long mRequestStartTime;
public void performRequest()
{
mRequestStartTime = System.currentTimeMillis(); // set the request start time just before you send the request.
JsonObjectRequest request = new JsonObjectRequest(URL, PARAMS,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
// calculate the duration in milliseconds
long totalRequestTime = System.currentTimeMillis() - mRequestStartTime;
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
long totalRequestTime = System.currentTimeMillis() - mRequestStartTime;
}
});
requestQueue.add(request);
}
关于android - 查找 volley 请求响应时间 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29386249/