這裏我想知道爲什麼getHeaders()
和getParams()
函數沒有被使用和工作。排球庫android-getHeaders()永遠不會被使用&getParams()永遠不會被使用
private String tag_json_obj = "jobj_req";
ProgressDialog pDialog = new ProgressDialog(this);
String tag_json_obj = "json_obj_req";
String url = "https://api.abc.xyz.com:3021/login";
pDialog.setMessage("Loading...");
pDialog.show();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
url, obj,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(AbcLogin.class.getSimpleName(), response.toString());
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(AbcLogin.class.getSimpleName(), "Error: " + error.getMessage());
// hide the progress dialog
pDialog.hide();
}
});
/**
* Passing some request headers
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
return headers;
}
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("user", "abc12");
params.put("password", "xyzan");
return params;
}
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
我必須在代碼中傳遞標題和參數。
使用StringRequest代替JsonObjectRequest –
我試過使用StringRequest,但它說不能解析構造函數。 – Prateekro