使用 http volley 发出获取请求时的空响应

Empty response when when making get request with http volley

我正在使用 volley 从 http url 发送和检索 json 数据,但是当收到响应时我收到一个空的吐司,url 是正确的,'http://systems.syspearl.com/api' 但我没有收到任何回复。下面是我用过的代码。

     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;

}

我研究了这个问题,我发现最接近的是这个 遗憾的是在这个 post 中选择的解决方案是使用字符串请求发送 json,我不能这样做是因为数据必须以这种格式

发送到 url
     {
    “amount”:500,
    “merchant_id”:”104”,
    “narrative”:”John”,
    “reference”:”Steven”
  }

后者 post 中的其他答案还建议向 http 添加一个 s,这不是我要发送到的 url。请提供帮助

你上面的 url http://systems.syspearl.com/api 正在响应 url not found(404)...可能是你的问题..请检查你的 url 路径和再试一次... 或者,如果您的回复为空,可能是服务器从不发送回复....因此您可以检查邮递员以进行确认

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