I my swift app . I want to create a request POST with alamofire
The request
$ curl \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-X POST -d '{ "user": { "email": "[email protected]", "password": "1234" } }' \
http://localhost:3000/users/sign_in
My code
let URL = NSURL(string: "https://lobo-api.herokuapp.com/users/sign_up")!
let mutableURLRequest = NSMutableURLRequest(URL: URL)
mutableURLRequest.HTTPMethod = "GET"
let parameters = ["user": ["email": "[email protected]", "password": "OPOPO"]]
var JSONSerializationError: NSError? = nil
mutableURLRequest.HTTPBody = NSJSONSerialization.dataWithJSONObject(parameters, options: nil, error: &JSONSerializationError)
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Accept")
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
Alamofire.request(mutableURLRequest).responseJSON { (request, response, data, error) in
println(error)
println(response)
println(data)
println(error)
}
I have got this error
Optional( { URL: https://lobo-api.herokuapp.com/users/sign_up } { status code: 404, headers {
Connection = "keep-alive";
"Content-Length" = 1564;
"Content-Type" = "text/html; charset=utf-8";
Date = "Sun, 05 Apr 2015 19:54:11 GMT";
Server = Cowboy;
Via = "1.1 vegur";
"X-Request-Id" = "12df8182-c91e-439f-b773-2b2e48f3f0c6";
"X-Runtime" = "0.007897";
} })
nil
Optional(Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x170678500 {NSDebugDescription=Invalid value around character 0.})
POST, right? - mattt