android volley 发送 POST 请求

Map<String, String> params = new HashMap<String, String>();
params.put("fromUser", "lesliefang");
params.put("toUser", "xiaojun");

JsonObjectRequest newMissRequest = new JsonObjectRequest(
    Request.Method.POST, "http://127.0.0.1:8080/users",
    new JSONObject(params), new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject jsonobj) {

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

volley 将 200 201 等视为成功的请求,而将  204 400 404 等视为失败的请求,会回调到 ErrorListener 中。

android volley 发送 POST 请求

时间: 2024-08-03 04:15:12

android volley 发送 POST 请求的相关文章

基于Android Volley的网络请求工具

基于Android Volley的网络请求工具. 一.说明 AndroidVolley,Android Volley核心库及扩展工程.AndroidVolleySample,网络请求工具示例工程.Release,jar包.直接下载 二.Volley基本处理流程: 1.应用初始化Volley.2.Volley创建一个RequestQueue.NetworkDispatcher组及Network.3.RequestQueue即一个Request队列,RequestQueue会创建一个Executor

Android URLConnection发送Get请求 HttpGet封装

一.使用URLConnection发送Get请求 1.与服务器建立连接: URLConnection connection=new URL("https://www.baidu.com/").openConnection(); 2.设置请求头(Cookie亦可通过请求头设置): connection.setRequestProperty("Referer","https://www.baidu.com/"); connection.setRequ

volley 发送post请求

public static void postNewComment(Context context,final UserAccount userAccount,final String comment,final int blogId,final int postId){ mPostCommentResponse.requestStarted(); RequestQueue queue = Volley.newRequestQueue(context); StringRequest sr = n

Android系列之网络(一)----使用HttpClient发送HTTP请求

[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4004983.html 联系方式:[email protected] 一.HTTP协议初探: HTTP(Hypertext Transfer Protocol)中文 “超文本传输协议”,是一种为分布式,合作式,多媒体信息系统服务,面向应用层的协议,是Internet上目前使用最广泛的应用层协议,它基

android volley框架

1 Volley发送get请求: [java] view plaincopy public void getJson() { String url = "http://"+host+":8080/web/json.jsp?username=xjs&password=123456"; mQueue.add(new JsonObjectRequest(Method.GET, url, null, new Listener<JSONObject>() 

Android Volley+OkHttp3+Gson 开源库的封装

博客将按照下面的步骤介绍Volley的重新封装: 1.OkHttp3的关于Volley的HttpStack实现 2.HttpRequest的实现和HttpListener回调监听的封装 3.Volley原始的Request的Wrap 4.各种方式的请求的重新实现 5.统一请求的实现 6.使用 所需依赖: compile 'com.android.volley:volley:1.0.0' compile 'com.squareup.okio:okio:1.7.0' compile 'com.squ

Android应用中网络请求库Volley的使用

接上文,这次来说一下如何使用Volley,会给出一些范例,和原理 Volley使用 StringRequest // 初始化一个请求队列,RequestQueue是volley库的类 RequestQueue queue = Volley.newRequestQueue(this); String url ="http://www.baidu.com"; //定义一个字符串型请求队列,需要传递4个参数分别是:url, 请求的方式(get, post..),响应成功的处理函数匿名对象,

Android Volley 的基本使用/设置HTTP请求参数、apikey

最近在做一个Android的新闻客户端,感觉收获颇丰. 这里分享一下Volley获取网络数据的方法 Volley是Google I/O 2013推出的网络通信库,它的拓展性很强,使用它能使代码变得更健壮,Volley在提供了高性能网络通讯功能的同时,对网络图片加载也提供了良好的支持 下面主要介绍一下Volley的StringRequest的使用方法 简单的写法是这样的: 1 /** 2 * 获取网络数据 新闻卡片 3 */ 4 private void getNewsData(String Ne

Android面向HTTP协议发送get请求

/** * 採用get请求的方式 * * @param username * @param password * @return null表示求得的路径有问题,text返回请求得到的数据 */ public static String getRequest(String username, String password) { try { String path = "http://172.22.64.156:8080/0001AndroidWebService/LoginServlet?use