I am using volley to send and retrieve json data from an http url, however when getting the response I receive an empty toast, the url is correct, 'http://systems.syspearl.com/api' but I receive no response. Below is the code I have used.
JSONObject jsonobject = new JSONObject();
jsonobject.put("amount", "500");
jsonobject.put("merchant_id", "104");
jsonobject.put("narrative", "John");
jsonobject.put("reference", "Steven");
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.POST,url, jsonobject,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(Main9Activity.this, response.toString(), Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Main9Activity.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String >headers=new HashMap<String,String>();
headers.put(“Content-Type”, “application/json“);
headers.put(“AuthKey”, Auth);
return headers;
}
I have researched this issue and the closest thing I found was this https://stackoverflow.com/a/31613565/7871886 sadly in this post the chosen solution is to send the json using string request, which I cannot do because data must be sent to the url in this exact format
{
“amount”:500,
“merchant_id”:”104”,
“narrative”:”John”,
“reference”:”Steven”
}
Other answers in the latter post also suggest adding an s to http which is not the url I am sending to. Please render assistance