大家好,我现在正在尝试使用参数和标头将发送数据发送到服务器,以在标头和参数中发送令牌密钥,但结果是没有响应response = null我使用参数在没有登录和注册的情况下将数据发送到服务器使用标头,当我仅使用标头并使用get方法而不发送任何参数而仅在标头中发送令牌时成功工作,它成功检索数据,但是当同时发送(标头和参数)结果为null时……我尝试发送邮递员中使用params和header的数据可以成功工作,但是当使用volley null发送数据时是响应
//我的代码
StringRequest stringRequest=new StringRequest(Request.Method.POST, "api_-url", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, "yes", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, ""+error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("offer_id","1");
// params.put("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImMwMGY4ZDMzZmE5ZTI1Yjg3MGE1NDAzNjI4M2I2YTVjNGVmNjc1YWY5NmM1ZjE4NDEyZDcwMjFhYzI0NzIzZDljNDNhMWY1MTllYmJlZDIwIn0.eyJhdWQiOiIzIiwianRpIjoiYzAwZjhkMzNmYTllMjViODcwYTU0MDM2MjgzYjZhNWM0ZWY2NzVhZjk2YzVmMTg0MTJkNzAyMWFjMjQ3MjNkOWM0M2ExZjUxOWViYmVkMjAiLCJpYXQiOjE1NzE3NDAxMjIsIm5iZiI6MTU3MTc0MDEyMiwiZXhwIjoxNjAzMzYyNTIyLCJzdWIiOiI0OSIsInNjb3BlcyI6W119.CGTRSHVWa42lX4ovOuYYqX-qkaLB5ulkleFzVhS_3G4n0qr9Jtid2QF9ksPDY6Mfhjl9KwBqySE0PzUslnGXhpPeKPvpgvgBc3R1GjLXGehfZLq-ET6gYxqCXYNbbfSw65DQgFanfw_ISzdMa7ZfKXFcc9GQhfppPodD4TaZESLLM2DNhCmW5sW-wUaXxzt7Z08m4HYv4d4UbBkTbvQmg5i-e6Q2wElTMowI921JSPbuyH3tyAvLjBpE5FpvYPbxkgPY4v7ZmEhFL2-9ZPchOjzdn-CirGFPzpBCi6b9zTIs8fr-o3pUFgylJM5qI5G8DWPMWccPj_78edYK8Wnb-gyZ2QNXwhWuC1WsF2DTiYgYZacSmw2t90nJ20-o8acYaf7zeUP_4BF71G6FQ_rYu2xZWNuBSYCet0nPzoyV_7ilsD-PaoIBANanRI-SSo3l3RfnPvVB1IDJzQe3ykuSCYuwfqVv5CA_JXOKVDNbuV1uk-3e79oGY33_1sb1RgZDWd0M_LvHN7wqKxYd6ri-lmGG2fMx3HcCvBsqCSOQPHpwcYyOm8o-aH6scHPm4SQ5iUVN5VRIr5-FtU3zHM85nY0OCfP41ydp_0LWjn82cMl4R_zLFX3uAg56PSt67PSqWb-EkAPtXzvFwiyP5A7CAomleygyZlbQrAGI6cqp2yA");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
// params.put("Accept","application/json");
// params.put("Content-Type","application/json");
params.put("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImMwMGY4ZDMzZmE5ZTI1Yjg3MGE1NDAzNjI4M2I2YTVjNGVmNjc1YWY5NmM1ZjE4NDEyZDcwMjFhYzI0NzIzZDljNDNhMWY1MTllYmJlZDIwIn0.eyJhdWQiOiIzIiwianRpIjoiYzAwZjhkMzNmYTllMjViODcwYTU0MDM2MjgzYjZhNWM0ZWY2NzVhZjk2YzVmMTg0MTJkNzAyMWFjMjQ3MjNkOWM0M2ExZjUxOWViYmVkMjAiLCJpYXQiOjE1NzE3NDAxMjIsIm5iZiI6MTU3MTc0MDEyMiwiZXhwIjoxNjAzMzYyNTIyLCJzdWIiOiI0OSIsInNjb3BlcyI6W119.CGTRSHVWa42lX4ovOuYYqX-qkaLB5ulkleFzVhS_3G4n0qr9Jtid2QF9ksPDY6Mfhjl9KwBqySE0PzUslnGXhpPeKPvpgvgBc3R1GjLXGehfZLq-ET6gYxqCXYNbbfSw65DQgFanfw_ISzdMa7ZfKXFcc9GQhfppPodD4TaZESLLM2DNhCmW5sW-wUaXxzt7Z08m4HYv4d4UbBkTbvQmg5i-e6Q2wElTMowI921JSPbuyH3tyAvLjBpE5FpvYPbxkgPY4v7ZmEhFL2-9ZPchOjzdn-CirGFPzpBCi6b9zTIs8fr-o3pUFgylJM5qI5G8DWPMWccPj_78edYK8Wnb-gyZ2QNXwhWuC1WsF2DTiYgYZacSmw2t90nJ20-o8acYaf7zeUP_4BF71G6FQ_rYu2xZWNuBSYCet0nPzoyV_7ilsD-PaoIBANanRI-SSo3l3RfnPvVB1IDJzQe3ykuSCYuwfqVv5CA_JXOKVDNbuV1uk-3e79oGY33_1sb1RgZDWd0M_LvHN7wqKxYd6ri-lmGG2fMx3HcCvBsqCSOQPHpwcYyOm8o-aH6scHPm4SQ5iUVN5VRIr5-FtU3zHM85nY0OCfP41ydp_0LWjn82cMl4R_zLFX3uAg56PSt67PSqWb-EkAPtXzvFwiyP5A7CAomleygyZlbQrAGI6cqp2yA");
// params.put("Accept-Language", "fr");
return params;
}
};
stringRequest.setShouldCache(false);
RequestQueue requestQueue = Volley.newRequestQueue(this);
stringRequest.setRetryPolicy(new DefaultRetryPolicy(15000,
1,
1));
requestQueue.add(stringRequest);