15
如何在Swift中使用JSON主体发出HTTP Post请求
我正在尝试使用JSON正文进行HTTP发布请求: 如何能够将NSdictionnary添加到HTTP请求正文。 这是我的代码,它似乎无法正常工作。 var entry1 = Response(IdQuestion: 6510,IdProposition: 10,Time: 30) var entry2 = Response(IdQuestion: 8284,IdProposition: 10,Time: 30) Responses.append(entry1) Responses.append(entry2) let list = Responses.map { $0.asDictionary } let json = ["List":list,"IdSurvey":"102","IdUser":"iOSclient","UserInformation":"iOSClient"] let data : NSData = NSKeyedArchiver.archivedDataWithRootObject(json) NSJSONSerialization.isValidJSONObject(json) let myURL = NSURL(string: "http://www.myserver.com")! let request = NSMutableURLRequest(URL: myURL) request.HTTPMethod = "POST" …