Volley从服务器端请求字符串数据,图片数据,和JSON格式数据。Volley可以写出标准化的模板代码,并让我们更加关注于我们的业务逻辑,这对于我们的App来说是非常重要的。
Volley的优势:
- 自动的调度网络请求
- 多并发的网络请求
- 可以缓存http请求
- 支持请求的优先级
- 支持取消请求的API,可以取消单个请求,可以设置取消请求的范围域。
- 代码标准化,使开发者更容易专注于我们的业务的逻辑处理
- 更容易给UI填充来自网络请求的数据
- Volley可以是作为调试和跟踪的工具
Volley非常不适合大的文件流操作,例如上传和下载。因为Volley会把所有的服务器端返回的数据在解析期间缓存进内存。大量的下载操作可以考虑用DownLoaderManager和异步加载来实现。
Volley库的地址如下:
git clone https://android.googlesource.com/platform/frameworks/volley
2 > Volley的工作原理
3> 使用volley请求数据
3.1 利用StringRequest请求字符串数据
Volley提供了一个便利的方法Volley.newRequestQueue可以使用默认的设置创建一个RequestQueue,例如:
- finalTextView mTextView =(TextView) findViewById(R.id.text);
- ...
- // Instantiate the RequestQueue.
- RequestQueue queue =Volley.newRequestQueue(this);
- String url ="http://www.google.com";
- // Request a string response from the provided URL.
- StringRequest stringRequest =newStringRequest(Request.Method.GET, url,
- newResponse.Listener<String>(){
- @Override
- publicvoid onResponse(String response){
- // Display the first 500 characters of the response string.
- mTextView.setText("Response is: "+ response.substring(0,500));
- }
- },newResponse.ErrorListener(){
- @Override
- publicvoid onErrorResponse(VolleyError error){
- mTextView.setText("That didn't work!");
- }
- });
- // Add the request to the RequestQueue.
- queue.add(stringRequest);
3.2 利用ImageRequest请求图片
- publicclassMainActivityextendsActivity{
- privateImageView mImageView;
- @Override
- protectedvoid onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mImageView =(ImageView) findViewById(R.id.iv_image);
- }
- publicvoid requestImage(){
- // Retrieves an image specified by the URL, displays it in the UI.
- String url ="http://i.imgur.com/7spzG.png";
- ImageRequest request =newImageRequest(url,
- newResponse.Listener<Bitmap>(){
- @Override
- publicvoid onResponse(Bitmap bitmap){
- Toast.makeText(MainActivity.this,"success",1).show();
- mImageView.setImageBitmap(bitmap);
- }
- },0,0,null,newResponse.ErrorListener(){
- publicvoid onErrorResponse(VolleyError error){
- /*mImageView
- .setImageResource(R.drawable.image_load_error);*/
- }
- });
- Volley.newRequestQueue(getApplicationContext()).add(request);
- }
- }
3.3 使用NetworkImageView结合imageLoader加载网络图片
- <com.android.volley.toolbox.NetworkImageView
- android:id="@+id/networkImageView"
- android:layout_width="150dp"
- android:layout_height="170dp"
- android:layout_centerHorizontal="true"/>
- ImageLoader mImageLoader;
- ImageView mImageView;
- // The URL for the image that is being loaded.
- private static final String IMAGE_URL =
- "http://developer.android.com/images/training/system-ui.png";
- ...
- mImageView = (ImageView) findViewById(R.id.regularImageView);
- // Get the ImageLoader through your singleton class.
- mImageLoader = MySingleton.getInstance(this).getImageLoader();
- mImageLoader.get(IMAGE_URL, ImageLoader.getImageListener(mImageView,R.drawable.def_image, R.drawable.err_image));
- TextView mTxtDisplay;
- ImageView mImageView;
- mTxtDisplay = (TextView) findViewById(R.id.txtDisplay);
- String url = "http://my-json-feed";
- JsonObjectRequest jsObjRequest = new JsonObjectRequest
- (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- mTxtDisplay.setText("Response: " + response.toString());
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- // TODO Auto-generated method stub
- }
- });
- // Access the RequestQueue through your singleton class.
- MySingleton.getInstance(this).addToRequestQueue(jsObjRequest);
3.4 使用JsonObjectRequest请求json格式数据(个人感觉和StringRequest一样)
- TextView mTxtDisplay;
- ImageView mImageView;
- mTxtDisplay = (TextView) findViewById(R.id.txtDisplay);
- String url = "http://my-json-feed";
- JsonObjectRequest jsObjRequest = new JsonObjectRequest
- (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- mTxtDisplay.setText("Response: " + response.toString());
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- // TODO Auto-generated method stub
- }
- });
- // Access the RequestQueue through your singleton class.
- MySingleton.getInstance(this).addToRequestQueue(jsObjRequest);
4> 如何取消请求
给请求设置TAG,并放进请求队列
- public static final String TAG = "MyTag";
- StringRequest stringRequest; // Assume this exists.
- RequestQueue mRequestQueue; // Assume this exists.
- // 给请求设置tag
- stringRequest.setTag(TAG);
- // 把请求放进请求队列
- mRequestQueue.add(stringRequest);
在onstop方法中取消所有设置Tag的请求
- @Override
- protected void onStop () {
- super.onStop();
- if (mRequestQueue != null) {
- mRequestQueue.cancelAll(TAG);
- }
- }
注意:当取消请求的时候,onResponse和onErrorResponse方法将不会执行
5> 如何新建一个RequestQueue
5.1 RequestQueue的配置
- RequestQueue mRequestQueue;
- // 配置缓存大小
- Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
- // 设置网络请求方式(UrlConnection和HttpClient)
- Network network = new BasicNetwork(new HurlStack());
- //初始化RequestQueue
- mRequestQueue = new RequestQueue(cache, network);
- // 开启RequestQueue
- mRequestQueue.start();
- String url ="http://www.myurl.com";
- // Formulate the request and handle the response.
- StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- // Do something with the response
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- // Handle error
- }
- });
- // 把请求添加进请求队列
- mRequestQueue.add(stringRequest);
- HttpStack stack;
- ...
- // If the device is running a version >= Gingerbread...
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
- // ...use HttpURLConnection for stack.
- } else {
- // ...use AndroidHttpClient for stack.
- }
- Network network = new BasicNetwork(stack);
5.3 使用requestQueue的注意事项
- 如果你的项目要进行频繁的网路请求,你可以在application的onCreate方法中创建一个RequestQueue,google官方文档强烈建议我们把RequestQueue设计成单列模式。
- 但是要注意,在RequestQueue中的Context对象为applicationContext,而不是Activity对应的context对象,可以避免在activity中每次都去消费使用activity中的context对象。
- private static MySingleton mInstance;
- private RequestQueue mRequestQueue;
- private static Context mCtx;
- public static synchronized MySingleton getInstance(Context context) {
- if (mInstance == null) {
- mInstance = new MySingleton(context);
- }
- return mInstance;
- }
- public RequestQueue getRequestQueue() {
- if (mRequestQueue == null) {
- // getApplicationContext() is key, it keeps you from leaking the
- // Activity or BroadcastReceiver if someone passes one in.
- mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
- }
- return mRequestQueue;
- }
- public <T> void addToRequestQueue(Request<T> req) {
- getRequestQueue().add(req);
- }
- public ImageLoader getImageLoader() {
- return mImageLoader;
- }
- }
1> Volley是用来请求网络数据的,首先我们要准备好要传递的URL参数
- HashMap<String, String> params = new HashMap<String, String>();
- params.put("user_id", userId);
- params.put("count", count + "");
- params.put("since_time", timeSince);
- params.put("profile_user_id", profileUserId);
- String url = HttpConstant.DOMAIN_NORMAL + HttpConstant.FRIENDS_FANS_1;
2> 把URL拼凑成一个完整的链接
- public void get(String url, Map<String, String> data, String tag, final CallbackLightRequest<LightResponse> callback) {
- if (!ConfigRequests.isNetworkOkWithAlert(mContext)) {
- callNetworkError(tag, url, data, callback);
- return;
- }
- Map<String, String> defaultParams = ConfigRequests.getInstance().getDefaultParams();
- if (defaultParams != null && defaultParams.size() > 0) {
- data.putAll(defaultParams);
- }
- if (data != null && data.size() > 0) {
- url = url + "?" + RequestUtils.map2QueryString(data);
- }
- this._get(url, tag, callback);
- }
拼凑URl的方法:map2QueryString
- public class RequestUtils {
- /**
- * 生成QueryString,以 a=1&b=2形式返回
- */
- public static String map2QueryString(Map<String, String> map) {
- StringBuilder sb = new StringBuilder();
- String value;
- try {
- if (map != null && map.size() > 0) {
- for (Entry<String, String> entry : map.entrySet()) {
- value = "";
- value = entry.getValue();
- if (StringUtils.isEmpty(value)) {
- value = "";
- } else {
- value = URLEncoder.encode(value, Models.Encoding.UTF8);
- }
- sb.append(entry.getKey()).append("=").append(value)
- .append("&");
- }
- sb.deleteCharAt(sb.length() - 1);
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return sb.toString();
- }
3> 发送请求,并将请求放进Requestqueue中,我把请求统一封装在一个
AppRequest类中,这个类如下:
- private void _get(final String url, final String tag, final Callback callback) {
- LogUtils.e(TAG, url);
- StringRequest req = new StringRequest(Request.Method.GET, url,
- new Listener<String>() {
- @Override
- public void onResponse(String text) {
- LogUtils.i(TAG, text);
- if (callback != null) {
- LightResponse res = new LightResponse();
- res.tag = tag;
- res.url = url;
- res.status = Models.StatusCode.NetworkSuccess;
- res.setData(text);
- callback.onFinish(res);
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- if (callback != null) {
- LightResponse res = new LightResponse();
- res.tag = tag;
- res.url = url;
- res.status = Models.StatusCode.NetworkError;
- res.message = error.getMessage();
- callback.onFinish(res);
- }
- }
- }) {
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- /* 此处是相对于实际业务配置的 */
- return new HashMap<String, String>();
- }
- };
- mQueue.add(req);
- }
- try {
- request.get(url, params, "", new CallbackLightRequest<LightResponse>() {
- @Override
- public void call(LightResponse response) {
- if (response.isReplied()) {
- ApiBeans.Followers2 bean = GsonUtil.getFromStr(ApiBeans.Followers2.class, response.getText());//json解析
- if (bean != null && bean.data != null) {
- httpCallback.onResponse(bean.data);//请求成功
- } else {
- httpCallback.onFailure(new RequestFailure(RequestFailure.Type.parse), null);//解析异常
- }
- } else {
- httpCallback.onFailure(new RequestFailure(RequestFailure.Type.network), null);//网络异常
- }
- }
- });
- } catch (Exception ex) {
- httpCallback.onFailure(new RequestFailure(RequestFailure.Type.exception), ex);//异常处理
- }
- public interface HttpCallback<T> {
- void onResponse(T response);//成功回调
- void onFailure(RequestFailure failure, Exception ex);//异常处理
- }
- public class RequestFailure {
- public enum Type {
- network,//网络问题
- responseCode,//错误的返回码处理
- exception,//系统异常
- parse, //解析
- }
- public RequestFailure(Type type) {
- this.what = type;
- }
- public Type what;
- }
- public static void getFolowFansList(final Context context, final LightRequest request, String userId, String profileUserId,
- String timeSince, int count, final HttpCallback<ApiBeans.FollowerListObject<Fan>> httpCallback) {
- HashMap<String, String> params = new HashMap<String, String>();
- params.put("user_id", userId);
- params.put("count", count + "");
- params.put("since_time", timeSince);
- params.put("profile_user_id", profileUserId);
- String url = HttpConstant.DOMAIN_NORMAL + HttpConstant.FRIENDS_FANS_1;
- doRequest(request,url, data, httpCallback, ApiBeans.FollowerListObject.class);
- }
- private static <T> void doRequest(LightRequest request,
- String url, HashMap<String, String> params,
- final HttpCallback callback, final Class<?> cls) {
- try {
- request.get(url, params, "", new CallbackLightRequest<LightResponse>() {
- @Override
- public void call(LightResponse response) {
- if (response.isReplied()) {
- T bean = GsonUtil.getFromStr(cls, response.getText());
- if (bean != null) {
- callback.onResponse(bean);
- } else {
- callback.onFailure(new RequestFailure(RequestFailure.Type.parse), null);
- }
- } else {
- callback.onFailure(new RequestFailure(RequestFailure.Type.network), null);
- }
- }
- });
- } catch (Exception ex) {
- callback.onFailure(new RequestFailure(RequestFailure.Type.exception), null);
- }
- }
- model.getFasList(mContext, lightRequest, Global.userDetail.userId, profileUserId, thisTimeSince, count,
- new HttpCallback<ApiBeans.FollowerListObject<Fan>>() {
- @Override
- public void onResponse(ApiBeans.FollowerListObject<Fan> data) {
- try {
- //数据返回成功
- if (data.userList != null) {
- adapter.setIsAllLoaded(data.infoCount < Constant.FEED_DEFAULT_NUM);
- lv.setIfHasMore(data.infoCount, Constant.FEED_DEFAULT_NUM);
- if (isRefresh) {
- adapter.setDataList(data.userList);
- lv.setAdapter(adapter);
- } else {
- adapter.addDataList(data.userList);
- adapter.notifyDataSetChanged();
- }
- } else {
- //刷新失败
- if (isRefresh) {
- ToastModel.showRefreshFail(mContext);
- } else {
- ToastModel.showLoadMoreError(mContext);
- }
- }
- } catch (Exception e) {
- } finally {
- isDownloading = false;
- if (loadingView != null) {
- loadingView.setVisibility(View.GONE);
- loadingView = null;
- }
- refreshEnd();
- }
- }
- @Override
- public void onFailure(RequestFailure failure, Exception ex) {
- //网络异常
- if (failure.what == RequestFailure.Type.network) {
- ToastModel.showRed(mContext, R.string.tip_network_error);
- } else if (failure.what == RequestFailure.Type.parse) {
- //解析失败
- ToastModel.showRed(mContext, "解析失败");
- } else if (failure.what == RequestFailure.Type.exception) {
- //系统异常
- ToastModel.showRed(mContext, "系统异常");
- }
- }
- });
- }
(一) Volley的二次封装
- protected <T> void doSimpleRequest(String url, HashMap<String, String> params, final Class<?> clazz, final SimpleCallback callback) {
- String requestUrl = urlBuilder(url, params);
- Logger.e("url", requestUrl);
- Response.Listener<String> successListener = new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- try {
- T bean = GsonUtils.getFromStr(clazz, response);
- callback.onResponse(bean);
- } catch (Exception e) {
- callback.onError();
- }
- }
- };
- Response.ErrorListener errorListener = new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- callback.onError();
- }
- };
- StringRequest requestRequest = new StringRequest(url, params, successListener, errorListener);
- LeSportsApplication.getApplication().addHttpRequest(requestRequest);
- }
- <span style="font-size: 18px;">package com.lesports.common.volley.toolbox;
- import android.os.Looper;
- import com.google.gson.Gson;
- import com.google.gson.JsonSyntaxException;
- import com.lesports.common.volley.NetworkResponse;
- import com.lesports.common.volley.ParseError;
- import com.lesports.common.volley.Request;
- import com.lesports.common.volley.Response;
- import com.letv.core.log.Logger;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.UnsupportedEncodingException;
- import java.util.HashMap;
- /**
- * Created by liuyu8 on 2015/9/15.
- */
- public class MyGsonRequest<T> extends Request<T>{
- private final Logger mLogger = new Logger("GsonRequest");
- private final Gson gson = new Gson();
- private final Class<T> clazz;
- private Response.Listener<T> listener;
- /**
- * Make a GET request and return a parsed object from JSON. Assumes
- * {@link Request.Method#GET}.
- *
- * @param url
- * URL of the request to make
- * @param clazz
- * Relevant class object, for Gson's reflection
- */
- public MyGsonRequest(String url,HashMap<String, String> params,Class<T> clazz, Response.Listener<T> listener, Response.ErrorListener errorListener) {
- super(Request.Method.GET, url, params,errorListener);
- this.clazz = clazz;
- this.listener = listener;
- }
- /**
- * Make a GET request and return a parsed object from JSON. Assumes
- * {@link Request.Method#GET}.
- *
- * @param url
- * URL of the request to make
- * @param clazz
- * Relevant class object, for Gson's reflection
- */
- public MyGsonRequest(String url, Class<T> clazz, Response.Listener<T> listener, Response.ErrorListener errorListener) {
- super(Request.Method.GET, url, errorListener);
- this.clazz = clazz;
- this.listener = listener;
- }
- /**
- * Like the other, but allows you to specify which {@link Request.Method} you want.
- *
- * @param method
- * @param url
- * @param clazz
- * @param listener
- * @param errorListener
- */
- public MyGsonRequest(int method, String url, Class<T> clazz, Response.Listener<T> listener, Response.ErrorListener errorListener) {
- super(method, url, errorListener);
- this.clazz = clazz;
- this.listener = listener;
- }
- @Override
- protected void deliverResponse(T response) {
- if(listener != null){
- listener.onResponse(response);
- }
- }
- @Override
- protected Response<T> parseNetworkResponse(NetworkResponse response) {
- try {
- if(Looper.myLooper() == Looper.getMainLooper()){
- mLogger.e("数据是 ==>在主线程中解析的~");
- }else{
- mLogger.e("数据不是 ==>在主线程中解析的~");
- }
- String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
- JSONObject jsonObject = new JSONObject(json);
- if(null != jsonObject && jsonObject.has("code") && jsonObject.getInt("code") == 200){
- return Response.success(gson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response));
- }else{
- return Response.error(new ParseError());
- }
- } catch (UnsupportedEncodingException e) {
- return Response.error(new ParseError(e));
- } catch (JsonSyntaxException e) {
- mLogger.e("JsonSyntaxException ==== ");
- return Response.error(new ParseError(e));
- } catch (JSONException e) {
- return Response.error(new ParseError(e));
- }
- }
- @Override
- public void finish(final String tag) {
- super.finish(tag);
- listener = null;
- }
- }</span>
- /**
- * 优化:
- * (1)避免在主线程中解析json数据
- * (2)添加了取消请求方法
- *
- * @param tag
- * @param url
- * @param params
- * @param clazz
- * @param callback
- * @param <T>
- */
- protected <T> void doRequest(String tag, String url, HashMap<String, String> params, final Class<?> clazz, final HttpCallback callback) {
- String requestUrl = urlBuilder(url, params);
- Logger.e("BaseTVApi", requestUrl);
- callback.onLoading();
- Response.Listener<T> successListener = new Response.Listener<T>() {
- @Override
- public void onResponse(T bean) {
- if (bean != null) {
- callback.onResponse(bean);
- Logger.e("BaseTVApi", "request-->onResponse");
- } else {
- callback.onEmptyData();
- Logger.e("BaseTVApi", "request-->onEmptyData");
- }
- }
- };
- Response.ErrorListener errorListener = new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- callback.onError();
- Logger.e("BaseTVApi", "异常信息-->" + error.getMessage());
- }
- };
- GsonRequest requestRequest = new GsonRequest(url, params, clazz, successListener, errorListener);
- requestRequest.setTag(tag);
- LeSportsApplication.getApplication().addHttpRequest(requestRequest);
- }
(二)使用Volley内存泄露
- /**
- * 网络请求优化,取消请求
- * @param tag
- */
- public void cancelRequest(String tag){
- try {
- mRequestQueue.cancelAll(tag);
- }catch (Exception e){
- Logger.e("LeSportsApplication","tag =="+ tag + "的请求取消失败");
- }
- }
- <span style="font-size: 18px;"> @Override
- public void finish(final String tag) {
- super.finish(tag);
- listener = null;
- }</span>
- public void finish(final String tag) {
- if (mRequestQueue != null) {
- mRequestQueue.finish(this);
- }
- if (MarkerLog.ENABLED) {
- final long threadId = Thread.currentThread().getId();
- if (Looper.myLooper() != Looper.getMainLooper()) {
- // If we finish marking off of the main thread, we need to
- // actually do it on the main thread to ensure correct ordering.
- Handler mainThread = new Handler(Looper.getMainLooper());
- mainThread.post(new Runnable() {
- @Override
- public void run() {
- mEventLog.add(tag, threadId);
- mEventLog.finish(this.toString());
- }
- });
- return;
- }
- mEventLog.add(tag, threadId);
- mEventLog.finish(this.toString());
- } else {
- long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime;
- if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) {
- VolleyLog.d("%d ms: %s", requestTime, this.toString());
- }
- }
- mErrorListener = null;
- }
(三) 在onStop中取消请求
(四)嵌套请求
- <span style="font-size: 18px;"> private void requestUserSubscribesGame() {
- uid = LoginUtils.getUid();
- if (StringUtils.isStringEmpty(uid)) {
- return;
- }
- UserTVApi.getInstance().getUserSubscribeGameId(TAG, uid, new SimpleCallback<ApiBeans.SubScribeListModel>() {
- @Override
- public void onResponse(ApiBeans.SubScribeListModel bean) {
- SubScribeModel subScribeModel = bean.data;
- if (subScribeModel != null) {
- scribeGameEntrys = subScribeModel.getEntities();
- requestHallData();
- }
- }
- @Override
- public void onError() {
- Logger.e(TAG, "获取订阅信息失败...");
- }
- });
- }</span>
首先新建一个类FakeX509TrustManager:
public class FakeX509TrustManager implements X509TrustManager {
private static TrustManager[] trustManagers;
private static final X509Certificate[] _AcceptedIssuers = new
X509Certificate[] {};
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException {
//To change body of implemented methods use File | Settings | File Templates.
}
public boolean isClientTrusted(X509Certificate[] chain) {
return true;
}
public boolean isServerTrusted(X509Certificate[] chain) {
return true;
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return _AcceptedIssuers;
}
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
// TODO Auto-generated method stub
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new FakeX509TrustManager() };
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
}
}
然后在进行StringRequest之前设置:
FakeX509TrustManager.allowAllSSL();
mStringRequest = new StringRequest(Request.Method.POST,
url,
getDefaultSuccessListener(),
mErrorListener){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return params;
}
};
mRequestQueue.add(mStringRequest);