iphone - iOS swift Post request -


so want create post request following output:

"user"=>{"email"=>"test@test.com", "password"=>"[filtered]", "password_confirmation"=>"[filtered]"} 

instead get:

{"user[password_confirmation]"=>"[filtered]", "user[email]"=>"test@test.com", "user[password]"=>"[filtered]", "user"=>{}} 

this code use make post request:

let request = nsmutableurlrequest(url: nsurl(string: urlstring)!)         let session = nsurlsession.sharedsession()         let params = ["user[email]":username.text!, "user[password]":password.text!, "user[password_confirmation]":passwordrepeated.text!]          request.httpbody = try? nsjsonserialization.datawithjsonobject(params, options: [])         request.addvalue("application/json", forhttpheaderfield: "content-type")         request.addvalue("application/json", forhttpheaderfield: "accept")         request.httpmethod = "post"          let task = session.datataskwithrequest(request, completionhandler: { data, response, error -> void in              print(request.httpbody)             print(params)             print(error)             print(response)             print(data)         })          task.resume() 

so how correctly create params?

you composing params incorrectly.

do this,

   let params = [         "user": [             "email": username.text!,             "password": password.text!,             "password_confirmation": passwordrepeated.text!         ]     ] 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -