Today, when writing an interface for the mobile end, the server could not parse the JSON data returned by the iOS (the request was received on the server, but the JSON data in the request body could not be obtained)
I hope Daniel can answer it.
? The back-end code is
@RequestBody Loginmodule JSON
@RequestMapping (value = "/test"
, method = Requestmethod.post
)
@ResponseBody
Public seckillresult<long> Test (HttpServletRequest request) {
String id=request.getparameter ("id");
String name=request.getparameter ("name");
SYSTEM.OUT.PRINTLN (ID);
SYSTEM.OUT.PRINTLN (name);
System.out.println ("The chain has Come");
Date Now=new date ();
return new Seckillresult<long> (True,now.gettime ());
}
Send the request code in iOS below
NSString *[email protected] "http://192.168.1.254:8080/seckill/test";
Nsurl*url=[nsurl URLWITHSTRING:URLSTR];
Initializing a mutable request
Nsmutableurlrequest*requset=[nsmutableurlrequest Requestwithurl:url];
Setting the time-out period
requset.timeoutinterval=5;
[Email protected] "POST";
3. Set the request body
Nsdictionary *json1 [Email protected]{
@ "id": @ "123",
@ "name": @ "Li"
};
nsdata* data =[nsjsonserialization datawithjsonobject:json1 options:nsjsonwritingprettyprinted Error:nil];
Convert the stitched string to data, set the request body
Requset. Httpbody=data;
Nsurlsession*session=[nsurlsession Sharedsession];
Nsurlsessiondatatask*datatask=[session datataskwithrequest:requset completionhandler:^ (NSData * _Nullable data, Nsurlresponse * _nullable response, Nserror * _nullable error) {
if (Error==nil) {
Get the appropriate information
NSString *content=[[nsstring Alloc]initwithdata:data encoding:nsutf8stringencoding];
NSLog (@ "%@", content);
}else{
NSLog (@ "%@", error);
}
}];
[Datatask resume];
}
"Java Interactive Communication Group" group number 256242993
The mobile interface encountered the server cannot resolve the iOS end return?