Android Volley通话需要近8分钟才能得到回复

时间:2018-03-07 11:45:14

标签: android android-volley

我在android中调用一个API,而我的服务器在Azure上调用。

Volley差不多花了8分钟才得到回应。我没有得到任何时间我们的错误。我也试过这个,在解析对象时我试图传递null,但结果是一样的。我在POSTMAN的机器上尝试了相同的API,它立即响应(1148 ms)。

这是我的API调用:

Log.e("API","STARTED");
final long t1 = System.currentTimeMillis();
GenericRequest<SearchDto> searchRequest = new GenericRequest<SearchDto>
        (Request.Method.GET, APIUrls.get().Search(searchStr),
                SearchDto.class, null,
                new Response.Listener<SearchDto>() {
                    @Override
                    public void onResponse(SearchDto searchDto) {
                        System.out.println();
                       Log.e("Time",System.currentTimeMillis() - t1 +"");
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        String res = AppUtils.getVolleyError(MainActivity.this, error);
                        AppUtils.openSnackBar(drawer_layout, res);
                    }
                });

ApiService.get().addToRequestQueue(searchRequest);

这就是我解析凌空网络响应的方式:

@Override
    protected Response<T> parseNetworkResponse(NetworkResponse response) {
        // The magic of the mute request happens here
        if (muteRequest) {
            if (response.statusCode >= 200 && response.statusCode <= 299) {
                // If the status is correct, we return a success but with a null object, because the server didn't return anything
                return Response.success(null, HttpHeaderParser.parseCacheHeaders(response));
            }
        } else {
            try {
                // If it's not muted; we just need to create our POJO from the returned JSON and handle correctly the errors
                String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
                T parsedObject = gson.fromJson(json, clazz);
                return Response.success(parsedObject, HttpHeaderParser.parseCacheHeaders(response));
            } catch (UnsupportedEncodingException e) {
                return Response.error(new ParseError(e));
            } catch (JsonSyntaxException e) {
                return Response.error(new ParseError(e));
            }catch (Exception e){
                return Response.error(new ParseError(e));
            }
        }
        return null;
    }

0 个答案:

没有答案