volley的post请求

//volley发送post请
 2     private void volleypost() {
 3         String url = "http://apis.juhe.cn/idcard/index?";
 4         StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
 5             @Override
 6             public void onResponse(String s) {
 7
 8                 Log.i("aa", "post请求成功" + s);
 9                 Toast.makeText(MainActivity2.this, s, Toast.LENGTH_LONG).show();
10             }
11         }, new Response.ErrorListener() {
12             @Override
13             public void onErrorResponse(VolleyError volleyError) {
14                 Log.i("aa", "post请求失败" + volleyError.toString());
15                 Toast.makeText(MainActivity2.this, volleyError.toString(), Toast.LENGTH_LONG).show();
16             }
17         }) {
18             @Override
19             protected Map<String, String> getParams() throws AuthFailureError {
20                 HashMap<String, String> map = new HashMap<>();
21                 map.put("key", "bb97bfce9edee938aeac99cb503b76db");
22                 map.put("cardno", "43052419910615");
23                 return map;
24             }
25         };
26         request.setTag("volleypost");
27         MyApplication.getHttpQueue().add(request);
28     }
时间: 2024-12-30 17:24:20

volley的post请求的相关文章

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

基于Android Volley的网络请求工具

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

【Android】Volley做网络请求的几种用法

前言: 最近在将自己写的烂代码重构,以前使用的网络请求全是基于apache的HttpClient,简单使用还好,使用多了发现重复代码太多,而且每次使用都很繁琐,因此在网上找了半天网络请求的相关类库,最后还是确定使用Volley,于是现在记个使用笔记: Volley几个主要功能: 1. 普通String请求: 既然使用了网络请求,那么网络权限是必不可少的,在AndroidManifest.xml中添加: <uses-permission android:name="android.permi

Volley的Https请求

前提:volley框架的jar,服务端ssl证书文件(crt,cet,pem格式等) 如果没有volley,我们可以通过git clone下来.地址: https://android.googlesource.com/platform/frameworks/volley 我们再来看看volley提供的demo源码: git://github.com/ogrebgr/android_volley_examples.git 把demo源码中的toolsbox下的一些通用类复制到自己项目下,包括: S

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

volley中网络请求

首先使用Volley类创建 RequestQueue queue = Volley.newRequestQueue(this);  Making GET Requests 1 final String url = "http://httpbin.org/get?param1=hello"; 2 3 // prepare the Request 4 JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GE

封装Volley使Volley的每个请求都自动保存和发送Cookie

思路很简单,每次请求获取到服务器返回的response就解析头部获取cookie并保存,发送请求的时候就从本地读取cookie添加到头部发送给服务器 第一步,解析http response头部的cookie并保存,自定义一个Request并重写其parseNetworkResponse方法 /** * 解析数据,保存Cookie * @param response * @return */ @Override protected Response<JSONObject> parseNetwor

Android Volley解析(一)之GET、POST请求篇

一. Volley 的地位 自2013年Google I/O 大会上,Google 推出 Volley 之后,一直到至今,由于其使用简单.代码轻量.通信速度快.并发量大等特点,倍受开发者们的青睐. 先看两张图,让图片告诉我们 Volley 的用处: 第一张 Volley 的经典图 通过上图,我们可以发现 Volley适合网络通信频繁操作,并能同时实现多个网络通信. 第二张图 我们在以前在 ListView 的 item 中如果有网络请求,一般都是通过Task 异步任务来完成,并在完成之后通知 A

android网络请求库volley方法详解

使用volley进行网络请求:需先将volley包导入androidstudio中 File下的Project Structrue,点加号导包 volley网络请求步骤: 1. 创建请求队列       RequestQueue queue = Volley.newRequestQueue(this); 2.创建请求对象(3种) StringRequest request = new StringRequest(“请求方法”,“请求的网络地址”,“成功的网络回调”,“失败的网络回调”): Ima