如何使用Volley和StringRequest发送POST参数?

时间:2019-11-04 15:14:18

标签: android android-volley

我正在尝试通过邮寄发送值,但我不知道该怎么做。 这是我的密码

 public class ConnectionPost {
    public void getResponse(Context context, final String url, OnSuccessful successful, OnFailed failed) {
        final OnSuccessful onSuccessful = successful;
        final OnFailed onFailed = failed;
        RequestQueue queue = Volley.newRequestQueue(context);
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        onSuccessful.Successful(response);
                        Log.i("___check_res2", response);
                        Log.i("___check_res3", url);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                onFailed.Failed(error.getMessage());
            }
        });
        queue.add(stringRequest);
    }
}

0 个答案:

没有答案