Android Volley StringRequest
来源:互联网 发布:linux怎么ping百度 编辑:程序博客网 时间:2024/04/29 02:08
Android Volley
private void VerifyUserCredential() { String url= clsGlobal.ServiceUrl + "account/credentials"; RequestQueue queue = Volley.newRequestQueue(this); StringRequest request = new StringRequest( Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { if(response.equals("")) { Toast.makeText(LoginActivity.this,"用户名或密码错误,请重新检查", Toast.LENGTH_LONG).show(); }else { Gson gson = new Gson(); FormUser strUserInfo = gson.fromJson(response, FormUser.class); clsGlobal.StoreID = strUserInfo.getStore(); clsGlobal.UserID = strUserInfo.getUserName(); clsGlobal.UserName = strUserInfo.getFullName(); Intent intent=new Intent(LoginActivity.this,MenuActivity.class); startActivity(intent); } Log.d("", response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d("", error.getMessage()); if ((error instanceof TimeoutError) || (error instanceof NoConnectionError)) { Toast.makeText(LoginActivity.this,"网络请求超时!", Toast.LENGTH_LONG).show(); } else if (error instanceof AuthFailureError) { //TODO } else if (error instanceof ServerError) { //TODO Toast.makeText(LoginActivity.this,"404页面!", Toast.LENGTH_LONG).show(); } else if (error instanceof NetworkError) { //TODO } else if (error instanceof ParseError) { //TODO } } }){ @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> params = new HashMap<String, String>(); params.put("username", "1"); params.put("password", "1"); return params; } @Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> params = new HashMap<String, String>(); params.put("store", "1111"); //params.put("Content-Type", "application/json"); return params; } }; queue.add(request); }
Web Api
[HttpPost] [Route("account/credentials")] [APIExceptionFilter] public IHttpActionResult VerifyCredentials(UserCredentialRequest request) { string StoreId = System.Web.HttpContext.Current.Request.Headers["store"]; if (StoreId == null) return BadRequest(); var user = _UsersRepository.TableAsNoTracking .Where(x => x.StoreId == StoreId && x.UserId == request.username) .FirstOrDefault(); if (user == null || user.IsLocked) return Content(HttpStatusCode.NoContent, ""); if (!Cryptography.VerifyPassword(request.password, user.Password)) return Content(HttpStatusCode.NoContent, ""); var response = new UserCredentialResponse(); response.Store = StoreId; response.UserName = request.username; response.FullName = user.UserName; return Ok(response); }
0 0
- Android Volley StringRequest
- Android Volley - volley StringRequest編碼問題
- Android Volley - volley StringRequest編碼問題
- android之volley StringRequest null
- Android:简单封装Volley StringRequest
- android 解决volley中StringRequest返回乱码
- Volley发送StringRequest请求
- Volley的StringRequest()简用
- Android Volley的基本用法--StringRequest以及JsonReques
- Android Volley框架(一):StringRequest、JsonObjectRequest、JsonArrayRequest
- Android-Volley网络通信框架(StringRequest和JsonObjectRequset)
- Android-Volley网络通信框架(StringRequest & JsonObjectRequest)
- Android高级之Volley框架(一):StringRequest
- 【进阶android】Volley源码分析——Volley的工具【StringRequest】
- 【Volley】加载图片和StringRequest
- 初识Volley:JsonObjectRequest、StringRequest、RequestQueue
- Volley中StringRequest的用法
- Volley StringRequest和JSONObjectRequest使用几个细节
- Maven系列 1. Maven入门
- 想要设计gulp & webpack构建系统?看这儿!
- 【Session】深入分析session与cookie(1)
- 产品学习:Android人人车客户端架构
- Maven系列 2.设置Maven
- Android Volley StringRequest
- 虚拟机已死 “容器”才是未来?
- webpack-dev-server,模块化开发神器
- Maven系列 3.Maven依赖管理
- mysql 协议的退出命令包及解析
- Erlang api 文档在线查询功能上线
- Maven系列 4.Maven项目基础
- c++通过运算符[]重载实现一重和二重数组
- ORACLE 基础概念及代码