简体   繁体   English

如何检查请求何时发送?

[英]How to check when a request has been sent?

I'm sending a Volley StringRequest and it is taking upwards of three minutes to receive a response (but the response is status OK and the receiving action method works correctly). 我正在发送一个Volley StringRequest,它需要花费三分钟才能收到响应(但响应状态正常并且接收操作方法正常工作)。

Is there any way to check when the request has actually been SENT to the server (all the answers I've found about Volley requests talk about when the response has been received), so I can tell if it's just my phone taking 2 minutes to process the request before even transmitting or if the requestQueue is just taking a long time before it even gets to my request (though I only send one Volley request, on click, with priority set to IMMEDIATE). 有什么方法可以检查请求何时实际上已经发送到服务器(我发现有关Volley请求的所有答案都在谈论收到响应的时候),所以我可以判断这只是我的手机花了2分钟到甚至在传输之前处理请求,或者如果requestQueue在它甚至达到我的请求之前花了很长时间(尽管我只发送一个Volley请求,点击,优先级设置为IMMEDIATE)。

Server-side logs show the prior request (a webview form submission) arriving a full 2-3 minutes prior to the StringRequest but I'm not sure if the delay is on cloudflare's side, the ELB or somewhere else and I want to know if I can discard the source device as being at fault. 服务器端日志显示先前的请求(webview表单提交)在StringRequest之前2-3分钟到达,但我不确定延迟是在cloudflare端,ELB还是其他地方,我想知道是否我可以将源设备丢弃为有问题。

Code follows for reference: 代码如下:

public void sendPostRequest(Map<String,String> params, String option)
{
    RequestQueue MyRequestQueue = Volley.newRequestQueue(this);
    String url="";
    switch (option){
        //...
        case "dniImages": //This is the one
            url  = BuildConfig.REST_DNI_IMAGES_ENDPOINT ;
            break;
    }

    StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            try{
            JSONObject resp = new JSONObject(response);}
            catch(JSONException e){}
        }
    }

    , new com.android.volley.Response.ErrorListener() { 
        @Override
        public void onErrorResponse(VolleyError error) {
            switch (option){
                //...
                case "dniImages":
                    Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }) {
        @Override
        public Priority getPriority() {
            return Priority.IMMEDIATE;
        }

        @Override
        protected com.android.volley.Response<String> parseNetworkResponse(NetworkResponse response) {
            if (response.statusCode == 200) {
                if (option.equals("dniImages"))
                    Toast.makeText(getApplicationContext(), "Error uploading images", Toast.LENGTH_SHORT).show();
            }
            return super.parseNetworkResponse(response);
        }
        protected Map<String, String> getParams() {
            return params;
        }
        @Override
        public Map<String, String> getHeaders(){
            try {
                Map<String, String> headers = super.getHeaders();
                if (headers == null
                        || headers.isEmpty()) {
                    headers = new HashMap<String, String>();
                }
                this.addSessionCookie(headers); 
                return headers;
            }
            catch (AuthFailureError e)
            {
            }
            return new HashMap<String, String>();
        }

        /**
         * Adds session cookie to headers if exists.
         * @param headers
         */
        public final void addSessionCookie(Map<String, String> headers) {
            String cookies = CookieManager.getInstance().getCookie(BuildConfig.TIENDAMIA_URL);
            headers.put("cookie", cookies);
        }

    };
    MyRequestQueue.add(MyStringRequest);
}

To be honest i haven't worked with Volley , but recently we had some few bugs related to networking and one of the tools that helped me a lot was the Android Profiler . 说实话,我没有和Volley一起工作过,但是最近我们有一些与网络相关的错误,其中一个帮我很多的工具是Android Profiler I mean look at Network Profiler overview this is absolutely amazing. 我的意思是看看Network Profiler概述这绝对是惊人的。

Connection View: Lists files that were sent or received during the selected portion of the timeline across all of your app's CPU threads. 连接视图:列出在所有应用程序的CPU线程中所选时间线部分期间发送或接收的文件。 For each request, you can inspect the size, type, status, and transmission duration. 对于每个请求,您可以检查大小,类型,状态和传输持续时间。 You can sort this list by clicking any of the column headers. 您可以通过单击任何列标题对此列表进行排序。 You also see a detailed breakdown of the selected portion of the timeline, showing when each file was sent or received. 您还会看到时间轴选定部分的详细明细,显示每个文件的发送或接收时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM