小编use*_*017的帖子

在post post android android volley中发送form-urlencoded参数

我想用表单urlencoded参数创建一个POST JSONObjectRequest.我怎样才能做到这一点?我试过以下代码,但无济于事.

final String api = "http://api.url";
final JSONObject jobj = new JSONObject();
jobj.put("Username", "usr");
jobj.put("Password", "passwd");
jobj.put("grant_type", "password");

final JsonObjectRequest jor = new JsonObjectRequest(

    Request.Method.POST, 
    api, jobj, 
    new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            Toast.makeText(getApplicationContext(), "Login Successful!", Toast.LENGTH_LONG).show();
            //do other things with the received JSONObject
        }
    }, 
    new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_LONG).show();
        }
    }) {

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> pars = new HashMap<String, String>(); …
Run Code Online (Sandbox Code Playgroud)

android android-volley

38
推荐指数
3
解决办法
3万
查看次数

标签 统计

android ×1

android-volley ×1