在 http://www.sojson.com/httpRequest/ 上对http进行访问,将此访问在android中的应用
****************************************************************************************
对于上边的请求,在Android中这样写就可以成功:(请求参数是json,返回值也是json)
public void test(String customerId, String pinNumber){ String url = "https:xxxxxx"; Map<String, String> params = new HashMap<String, String>(); params.put("email", customerId); params.put("password",pinNumber); JSONObject json = new JSONObject(params);
//这里不用 JsonObjectRequest ,这个太多的坑了 StringRequest request = new StringRequest(Method.POST,url,json,new Response.Listener<String>() { @Override public void onResponse(String response) { try { JSONObject resp = new JSONObject(response); String success = resp.getString("success"); String msg = resp.getString("msg"); if(success.equals("true")){ //返回true,,意思是后台db中找到此用户,然后跳转到MainPagerActivity界面 Log.e("log","success return true , msg - :"+msg); }else{ //success = false,意思是后台db没有找到此用户 } } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.e("log","error"); } } ){ public Map<String, String> getHeaders() { HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Authorization", "xxxxxxxxxx"); return headers; } }; request.setRetryPolicy(new DefaultRetryPolicy(60 * 1000, 1, 1.0f)); request.setTag(this); mRequestQueue.add(request); }