The mobile interface encountered the server cannot resolve the iOS end return?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.