同步齐射请求并获取意外响应代码400并请求不发送到服务器

时间:2018-02-01 08:44:17

标签: java android http https android-volley

我对服务器的同步截击请求有400代码错误,但我不知道为什么。我搜索了所有问题,但答案对我不起作用。我用邮递员检查API,效果很好。

    public static String getResponce(final String Url, final List<NameValuePair> nameValuePairs) {

    String resulte = "";

    final RequestQueue requestQueue = Volley.newRequestQueue(MyApplication.getContext());


    RequestFuture<String> future = RequestFuture.newFuture();
    StringRequest request = new StringRequest(Request.Method.POST, Url, future, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();

        }
    }){


        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();

            for (int i = 0 ; i < nameValuePairs.size() ; i++){
                params.put(nameValuePairs.get(i).getName() , nameValuePairs.get(i).getValue());
            }

            Log.e("params" , params.toString());

            return params;

        }
    };
    requestQueue.add(request);

    try {

        resulte =  future.get(30 , TimeUnit.SECONDS); // this will block
    } catch (InterruptedException e) {
        // exception handling
    } catch (ExecutionException e) {
        // exception handling
        e.printStackTrace();
        e.getMessage();
    } catch (TimeoutException e) {
        e.printStackTrace();
    }

    return resulte;

}

nameValuePairs是我的请求参数,它在getParams()方法中添加到hashmap。

E/Volley: [327] BasicNetwork.performRequest: Unexpected response code 400 for https://www.goldfishschool.com/api/users/authentication

这是我的代码,请帮助我。

0 个答案:

没有答案