0

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

Bwalya
  • 118
  • 11

2 Answers2

1

your above url http://systems.syspearl.com/api is responding url not found(404)...may be that is your problem..please check your url path and try again... OR if your response is empty may be server never send a response....so you can check in postman for confirmation

unownsp
  • 727
  • 5
  • 19
0

The url http://systems.syspearl.com/api shows an error.... I would suggest first, try to make a simple volley request from the docs https://developer.android.com/training/volley/simple