【问题标题】:Volley throw 502 bad gateway凌空投掷 502 坏网关
【发布时间】:2017-07-08 04:43:38
【问题描述】:

我正在使用 Volley 发送 Get 方法。有时我有 502 bad gateway server error。我不知道是什么问题或如何解决我的问题

这是源代码

    public void polygonRequest(final String userID, final String secretKey) {
    showpDialog("loading");
    polygonModelList.clear();

    String url = ServerUtil.polygon+userID+"/"+secretKey;
    final JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    SavedPolygonJson polygonModel=new SavedPolygonJson();
                    polygonModel.setPolygonJson(response.toString());
                    polygonModel.saveInStorage();
                    parsePolygonRequest(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    hidepDialog();
                    showOneItemDialog(error.toString(),false);

                }
            });


    jsObjRequest.setRetryPolicy(new DefaultRetryPolicy(
            10000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    CoreApplication.getInstance().getRequestQueue().add(jsObjRequest);
}

当我使用浏览器发送我的请求时,我没有任何错误。我该如何解决这个错误... 我如何将浏览器的请求标头与 Volley 请求标头结合起来? 谢谢

【问题讨论】:

  • 不能发表评论,所以在这里发帖。这通常发生在总响应时间大于截击重试时间时

标签: android android-volley http-get


【解决方案1】:

如果您正在使用改造,请增加读取超时会话。 或者在 volley 的情况下,将请求时间会话从其默认值中增加

用于交叉检查,直接在网络浏览器中点击 url,并根据您设置的请求会话时间计算获取响应所需的时间

发生这种情况是因为如果您的网络库在预定义的请求时间没有得到响应,它会显示错误的网关 502

【讨论】:

    猜你喜欢
    • 2014-11-11
    • 1970-01-01
    • 2019-04-11
    • 2021-10-04
    • 2014-01-25
    • 2017-06-23
    • 2019-10-03
    • 2017-11-08
    • 2020-11-12
    相关资源
    最近更新 更多