【问题标题】:Empty response when when making get request with http volley使用 http volley 发出获取请求时的空响应
【发布时间】:2020-01-28 16:02:02
【问题描述】:

我正在使用 volley 从 http url 发送和检索 json 数据,但是当我收到一个空 toast 的响应时,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;

}

我已经研究过这个问题,我发现最接近的是https://stackoverflow.com/a/31613565/7871886 遗憾的是,在这篇文章中,选择的解决方案是使用字符串请求发送 json,我不能这样做,因为数据必须准确地发送到 url格式

     {
    “amount”:500,
    “merchant_id”:”104”,
    “narrative”:”John”,
    “reference”:”Steven”
  }

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

【问题讨论】:

    标签: java android android-volley


    【解决方案1】:

    您上面的 url http://systems.syspearl.com/api 正在响应 url not found(404)...可能是您的问题..请检查您的 url 路径并重试... 或者,如果您的响应为空,则服务器可能永远不会发送响应....所以您可以检查邮递员以进行确认

    【讨论】:

      【解决方案2】:

      网址http://systems.syspearl.com/api 显示错误......我建议首先尝试从文档https://developer.android.com/training/volley/simple 发出一个简单的截击请求

      【讨论】:

        猜你喜欢
        • 2019-09-10
        • 1970-01-01
        • 2016-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-21
        • 2015-01-12
        • 1970-01-01
        相关资源
        最近更新 更多