Curl and Java combine incoming Get.post,head requests,
For example: Curl's address:
Curl-l 127.0.0.1:8080/spacobj/core/do?acid=100-h "token:101hh"-H "Content-type:application/json"-X post-d {"TelNum" : "13521389587", "Pass": "' my12345 '", "Nick": "Tomorrow will be Better", "SMS": "' 7864AQ '"}
Note that the string in the JSON format must be "' inside is a string '"
The code obtained in Java is as follows:
@RequestMapping (value = "Do", method = Requestmethod.post)
Public String Mydo (
@RequestParam (value = "Acid", required = false, DefaultValue = "0") int acid,
@RequestHeader (value = "token", required = false, DefaultValue = "0") String token,
HttpServletRequest request, HttpServletResponse response)
Throws Unsupportedencodingexception, IOException, parseexception {
The following creates an object that accepts the data that the JSON passes over
T_account TAC = new T_account ();
StringBuilder sb = new StringBuilder ();
BufferedReader in = new BufferedReader (New InputStreamReader (
Request.getinputstream (), "UTF-8"));
String line = null;
while (line = In.readline ()) = null) {
Sb.append (line);
String json = sb.tostring ();
Jsonobject Jsonobject = Jsonobject.fromobject (JSON);
Iterator ite = Jsonobject.keys ();
Iterate over the Jsonobject data and receive it with the object. By key, it is the field of the object that accepts the JSON request from post.
while (Ite.hasnext ()) {
String key = Ite.next (). toString ();
if (Key.equals ("Telnum")) {
Tac.settelnum (Jsonobject.get (key). ToString ());
}
if (Key.equals ("pass")) {
Tac.setpass (Jsonobject.get (key). ToString ());
}
if (Key.equals ("Nick")) {
Tac.setnick (Jsonobject.get (key). ToString ());
}
if (key.equals ("SMS")) {
Tac.setsms (Jsonobject.get (key). ToString ());
}
String value = Jsonobject.get (key). ToString ();
}
}
Curl Javassm Format method for passing in a JSON array