这里我没有得到任何响应是否有任何错误在这个代码中我使用了API中的两个参数我已经存储在params虽然在Error中进来**新的JSONObject(params)** API工作正常但是
onErrorResponse:错误:
HashMap<String, String> params = new HashMap<String, String>();
params.put("employeeId", "dd25ec65-e276-488b-92b1-a324a1d4cc18");
private void getData(){
//Showing a progress dialog
final ProgressDialog loading = ProgressDialog.show(this,"Loading Data", "Please wait...",false,false);
//Creating a json obj request
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Config.DATA_URL,new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
VolleyLog.v("Response:%n %s",response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
}
});
//Creating request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(jsonObjectRequest);
}
答案 0 :(得分:0)
我建议像这样使用:
private void getData(){
//Showing a progress dialog
final ProgressDialog loading = ProgressDialog.show(this,"Loading Data", "Please wait...",false,false);
//Creating a json obj request
StringRequest dataRequest = new StringRequest(Request.Method.POST,
Config.DATA_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
loading.dismiss();
Log.v("Response",response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
loading.dismiss();
Log.e("Error: ", error.getMessage());
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> sendMap = new HashMap<String, String>();
sendMap.put("employeeId", "dd25ec65-e276-488b-92b1-a324a1d4cc18");
return sendMap;
}
};
//Creating request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(dataRequest);
}
如果有任何错误,请告诉我.....