{"id":1677,"date":"2017-06-02T19:22:09","date_gmt":"2017-06-02T11:22:09","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=1677"},"modified":"2017-06-02T19:22:39","modified_gmt":"2017-06-02T11:22:39","slug":"android-%e7%bd%91%e7%bb%9c%e8%bf%9e%e6%8e%a5%e5%ba%93volley%e7%9a%84get%e5%92%8cpost%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/1677","title":{"rendered":"android \u7f51\u7edc\u8fde\u63a5\u5e93volley\u7684get\u548cpost\u7684\u4f7f\u7528"},"content":{"rendered":"

 <\/p>\n

\u9996\u5148\u6dfb\u52a0\uff1a<\/p>\n

private RequestQueue mRequestQueue;<\/p>\n

\u5728oncreate\u6dfb\u52a0<\/p>\n

mRequestQueue = Volley.newRequestQueue(this);<\/p>\n


\n

JsonObjectRequest post\u8bf7\u6c42\u5e76\u7528\u6dfb\u52a0\u53c2\u6570
\n
\nHashMap<String,String> map = new HashMap<String,String>();
\nmap.put(\"customer_type\",strCustomerType);
\nmap.put(\"customer_code\",strCustomerCode);
\nmap.put(\"student_code\",strStudentCode);
\nmap.put(\"student_password\",strStudentPassword);<\/code><\/p>\n

JSONObject params = new JSONObject(map);<\/p>\n

String strURL = DaJuanApp.getBindURL(strCustomerType,strCustomerCode) + DaJuanApp.getTokenQueryParam(BindActivity.this);
\n\/\/Toast.makeText(BindActivity.this, strURL, Toast.LENGTH_SHORT).show();
\n\/\/
\n\/*
\nJsonObjectRequest jsonObjectRequest = new JsonObjectRequest( Request.Method.POST,
\nstrURL,
\nparams,
\nnew Listener() {
\n@Override
\npublic void onResponse(JSONObject jsonObject) {<\/p>\n

try{<\/p>\n

String str = jsonObject.get(“code”).toString() + “\uff1a” + jsonObject.get(“message”).toString();<\/p>\n

if ( jsonObject.get(“code”).toString().equals(“200″)) {
\n\/\/\u6210\u529f
\nToast.makeText(BindActivity.this, str, Toast.LENGTH_SHORT).show();
\n\/\/DaJuanApp.setConfigValue(LoginActivity.this,”Telephone”,strTelephone);<\/p>\n

}
\nelse
\n{
\n\/\/\u5931\u8d25
\n\/\/Toast.makeText(RegisterActivity.this, jsonObject.get(“message”).toString(), Toast.LENGTH_SHORT).show();
\nboolean bRes = DaJuanApp.getInstance().notLogin(BindActivity.this,jsonObject);
\nif (bRes){
\nreturn;
\n}
\nDialog dialog = new AlertDialog.Builder(BindActivity.this)
\n.setTitle(“\u63d0\u793a”)
\n\/\/.setIcon(R.drawable.questionmark)
\n.setMessage(str)
\n.setPositiveButton(“\u786e\u5b9a”, new DialogInterface.OnClickListener() {
\n@Override
\npublic void onClick(DialogInterface dialog, int which) {<\/p>\n

}
\n})
\n.create();
\ndialog.show();<\/p>\n

}<\/p>\n

}
\ncatch (JSONException e)
\n{
\nToast.makeText(BindActivity.this, e.getMessage().toString(), Toast.LENGTH_SHORT).show();<\/p>\n

}
\n}
\n},
\nnew Response.ErrorListener() {
\n@Override
\npublic void onErrorResponse(VolleyError volleyError) {<\/p>\n

String str = volleyError.toString();<\/p>\n

Toast.makeText(BindActivity.this, str, Toast.LENGTH_LONG).show();<\/p>\n

}
\n});
\nmRequestQueue.add(jsonObjectRequest);<\/p>\n


\n

StringRequest post\u8bf7\u6c42\u5e76\u6dfb\u52a0\u53c2\u6570\uff1a<\/p>\n

StringRequest sr = new StringRequest(\r\n        Request.Method.POST,\r\n        strURL,\r\n        new Response.Listener<String>() {\r\n            @Override\r\n            public void onResponse(String response) {                                \r\n                Toast.makeText(BindActivity.this, response, Toast.LENGTH_LONG).show();\r\n                tvInfo.setText(response);\r\n            }\r\n        }, new Response.ErrorListener() {\r\n            @Override\r\n            public void onErrorResponse(VolleyError error) {\r\n                \/\/Toast.makeText(BindActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();\r\n                \/\/tvInfo.setText(error.getMessage().toString());\r\n                tvInfo.setText(\"\u8bf7\u6c42\u9519\u8bef\");\r\n            }\r\n        }){\r\n    @Override\r\n    protected Map<String, String> getParams()  {\r\n\r\n        HashMap<String,String> map = new HashMap<String,String>();\r\n        map.put(\"customer_type\",\"school\");\r\n        map.put(\"customer_code\",\"cszx\");\r\n        map.put(\"student_code\",\"26272062\");\r\n        map.put(\"student_password\",\"dajuan2017\");\r\n\r\n        \/\/JSONObject params = new JSONObject(map);\r\n        return map;\r\n    }\r\n\r\n\r\n};\r\nmRequestQueue.add(sr);<\/pre>\n","protected":false},"excerpt":{"rendered":"

  \u9996\u5148\u6dfb\u52a0\uff1a private RequestQueue mRequestQueue; \u5728oncreate\u6dfb\u52a0 mRequestQueue = Volley.newRequestQueue(this); JsonObjectRequest post\u8bf7\u6c42\u5e76\u7528\u6dfb\u52a0\u53c2\u6570 HashMap<String,String> map = new HashMap<String,String>(); map.put(“customer_type”,strCustomerType); map.put(“customer_code”,strCustomerCode); map.put<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[277,1,9],"tags":[282,283,281,280,284],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1677"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=1677"}],"version-history":[{"count":2,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1677\/revisions"}],"predecessor-version":[{"id":1679,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1677\/revisions\/1679"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=1677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=1677"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=1677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}