1. code snippet to format:
1: HttpPost request = new HttpPost(url);
2: // encapsulate a JSON object first
3: JSONObject param = new JSONObject();
4: param.put("name", "rarnu");
5: param.put("password", "123456");
6: // bind to the request entry
7: StringEntity se = new StringEntity(param.toString());
8: request.setEntity(se);
9: // send the request
10: HttpResponse httpResponse = new DefaultHttpClient().execute(request);
11: // The response string, which is saved in JSON format.
12: String retSrc = EntityUtils.toString(httpResponse.getEntity());
13: // generate a JSON object
14: JSONObject result = new JSONObject( retSrc);
15: String token = result.get("token");
-------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
2. insert Code (a few languages are supported ):
Httppost request = new httppost (URL); // encapsulate a JSON object jsonobject Param = new jsonobject (); Param. put ("name", "rarnu"); Param. put ("password", "123456"); // bind to the request entry stringentity Se = new stringentity (Param. tostring (); Request. setentity (SE); // send the request httpresponse = new defaulthttpclient(.exe cute (request); // The response string, which is also a string retsrc = entityutils stored in JSON format. tostring (httpresponse. getentity (); // generate JSON object jsonobject result = new jsonobject (retsrc); string token = result. get ("token ");
-------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
3. Source Code Format (cannot be copied ):
HttpPost request = new HttpPost(url);
// Encapsulate a JSON object first
JSONObject param = new JSONObject();
param.put("name", "rarnu");
param.put("password", "123456");
// Bind to the request entry
StringEntity se = new StringEntity(param.toString());
request.setEntity(se);
// Send the request
HttpResponse httpResponse = new DefaultHttpClient().execute(request);
// Obtain the response string, which is also the data saved in JSON format
String retSrc = EntityUtils.toString(httpResponse.getEntity());
// Generate a JSON object
JSONObject result = new JSONObject( retSrc);
String token = result. Get ("token ");
-------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
4. Insert Source Code Plug-in:
Httppost request = new httppost (URL); // encapsulate a JSON object jsonobject Param = new jsonobject (); Param. put ("name", "rarnu"); Param. put ("password", "123456"); // bind to the request entry stringentity Se = new stringentity (Param. tostring (); Request. setentity (SE); // send the request httpresponse = new defaulthttpclient(.exe cute (request); // The response string, which is also a string retsrc = entityutils stored in JSON format. tostring (httpresponse. getentity (); // generate JSON object jsonobject result = new jsonobject (retsrc); string token = result. get ("token ");
-------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
5. Insert a code block (Multiple blogs can be customized)
Httppost request = new httppost (URL); // encapsulate a JSON object jsonobject Param = new jsonobject (); Param. put ("name", "rarnu"); Param. put ("password", "123456"); // bind to the request entry stringentity Se = new stringentity (Param. tostring (); Request. setentity (SE); // send the request httpresponse = new defaulthttpclient(.exe cute (request); // The response string, which is also a string retsrc = entityutils stored in JSON format. tostring (httpresponse. getentity (); // generate JSON object jsonobject result = new jsonobject (retsrc); string token = result. get ("token ");
-------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
Cnblog effect (advantage over csdn in 4th plug-in ):
http://www.cnblogs.com/dartagnan/archive/2011/04/02/2003895.html
51cto effect (terrible !!!)
http://dadoneo.blog.51cto.com/2908573/534096