我正在尝试通过android调用API,它给出了无效的请求错误。
同时API在POSTMAN中给出正确的结果。
我正在使用以下代码。以下代码有问题。
String url ="http://apiaddress";
// POST parameters
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "test");
JSONObject jsonObj = new JSONObject(params);
// Request a json response from the provided URL
JsonObjectRequest jsonObjRequest = new JsonObjectRequest
(Request.Method.POST, url, jsonObj, new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
System.out.print("JSOn Object:"+jsonObj.toString());
}
});
答案 0 :(得分:0)
在Volley中,JsonObjectRequest
似乎不适用于POST请求。请改用StringRequest
。
也请选中此answer。
此外,override
的{{1}}方法getParams
并以StringRequest
的形式返回您的参数。