Java 添加带有截击请求和响应的自定义标头为;数据“:&引用;此字段为必填字段;

Java 添加带有截击请求和响应的自定义标头为;数据“:&引用;此字段为必填字段;,java,android,android-studio,android-volley,Java,Android,Android Studio,Android Volley,我刚开始使用截击请求和自定义请求,这里是我用来发送自定义头的代码的和平。标题必须是 headers.put(“接受”、“应用程序/json”); headers.put(“内容类型”、“应用程序/json”) 当我与邮递员点击这个url时,它工作正常 邮递员中的行数据 及 标题 如果我这边有任何问题,请告诉我。StringRequest StringRequest=new StringRequest(Request.Method.POST, StringRequest stringReq

我刚开始使用截击请求和自定义请求,这里是我用来发送自定义头的代码的和平。标题必须是 headers.put(“接受”、“应用程序/json”); headers.put(“内容类型”、“应用程序/json”)

当我与邮递员点击这个url时,它工作正常

邮递员中的行数据

及 标题

如果我这边有任何问题,请告诉我。

StringRequest StringRequest=new StringRequest(Request.Method.POST,
  StringRequest stringRequest = new StringRequest(Request.Method.POST,
        WebConstants.BASE_URL + method,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> headers = new HashMap<>();
        headers.put("Accept", "application/json");
        headers.put("Content-Type", "application/json; charset=utf-8");
        return headers;
    }
    @Override
    protected Map<String, String> getParams() {
      Map<String, String> map = new HashMap<>();
      map.put("firstname", "sandeep");
      map.put("lastname", "sada");
     map.put("gender", "d");
    map.put("country", "sdfasiio");
    map.put("zipcode", "test");
    map.put("email", "testmail@mail.com");
    map.put("password", "0");
    map.put("referral_code", "0");
    map.put("requested_plan", "0");

    Log.e("Map", map.toString());
            return map;
        }
};
stringRequest.setShouldCache(false);
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
        DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2,
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
WebConstants.BASE_URL+方法, 新的Response.Listener(){ @凌驾 公共void onResponse(字符串响应){ } }, 新的Response.ErrorListener(){ @凌驾 公共无效onErrorResponse(截击错误){ } }) { @凌驾 公共映射getHeaders()引发AuthFailureError{ Map headers=newhashmap(); headers.put(“接受”、“应用程序/json”); headers.put(“内容类型”、“应用程序/json;字符集=utf-8”); 返回标题; } @凌驾 受保护的映射getParams(){ Map Map=newhashmap(); 地图放置(“名字”、“sandeep”); 地图放置(“姓氏”、“萨达”); 地图放置(“性别”、“d”); 地图放置(“国家”、“sdfasiio”); map.put(“zipcode”、“test”); map.put(“电子邮件”)testmail@mail.com"); 地图放置(“密码”、“0”); 地图放置(“参考代码”,“0”); 地图放置(“请求的平面图”、“0”); Log.e(“Map”,Map.toString()); 返回图; } }; stringRequest.setShouldCache(false); stringRequest.setRetryPolicy(新的DefaultRetryPolicy( DefaultRetryPolicy.DEFAULT\u TIMEOUT\u MS*2, DefaultRetryPolicy.DEFAULT\u最大重试次数, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); RequestQueue RequestQueue=Volley.newRequestQueue(上下文); 添加(stringRequest);
如何与邮递员配合使用?可以显示屏幕截图吗?应该将主体参数作为键值对而不是json发送string@VladyslavMatviienko添加了这一点,Vivek让我检查您的解决方案。显示请求的主体。我想看看你是如何发送邮件的data@VivekMishra谢谢,但问题还没有解决是的,你在里面做了什么改变
E/res: {
        "success": false,
        "data": "This field is required"
    }
  StringRequest stringRequest = new StringRequest(Request.Method.POST,
        WebConstants.BASE_URL + method,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> headers = new HashMap<>();
        headers.put("Accept", "application/json");
        headers.put("Content-Type", "application/json; charset=utf-8");
        return headers;
    }
    @Override
    protected Map<String, String> getParams() {
      Map<String, String> map = new HashMap<>();
      map.put("firstname", "sandeep");
      map.put("lastname", "sada");
     map.put("gender", "d");
    map.put("country", "sdfasiio");
    map.put("zipcode", "test");
    map.put("email", "testmail@mail.com");
    map.put("password", "0");
    map.put("referral_code", "0");
    map.put("requested_plan", "0");

    Log.e("Map", map.toString());
            return map;
        }
};
stringRequest.setShouldCache(false);
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
        DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2,
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);