I'm struggling :( to make an HTTP post request with a custom JSON Body, I have tried Alamofire with the code :
let list = [[Time: 30, IdQuestion: 6510, idProposition: 10], [Time: 30, IdQuestion: 8284, idProposition: 10]]
let json = ["List":list,"IdQuiz":"102","IdUser":"iOSclient","UserInformation":"iOSClient"]
let data = NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions.PrettyPrinted,error:nil)
let jsons = NSString(data: data!, encoding: NSUTF8StringEncoding)
Alamofire.request(.POST, "http://myserver.com", parameters: [:], encoding: .Custom({
(convertible, params) in
var mutableRequest = convertible.URLRequest.copy() as! NSMutableURLRequest
mutableRequest.HTTPBody = jsons!.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
return (mutableRequest, nil)
}))
.response { request, response, data, error in
let dataString = NSString(data: data!, encoding:NSUTF8StringEncoding)
println(dataString)
}
But this is not working, I should delete the list to make it work, Why I can't have a list in my JSON body
my JSON body looks like :
{
"IdQuiz" : 102,
"IdUser" : "iosclient",
"User" : "iosclient",
"List":[
{
"IdQuestion" : 5,
"IdProposition": 2,
"Time" : 32
},
{
"IdQuestion" : 4,
"IdProposition": 3,
"Time" : 9
}
]
}
Is there any library or anything you recommend to make this HTTP post request work ?
That works fine
Then I wrote a test php file to view the result got from app:
And I see
Function I used to make POST-request is below: