Good morning, I looked for several sites a way to do a POST request for a server, found several ways and tried all of them, but none worked. I can receive the data from the page and even send GET variables in the URL, but POST variables are simply not sent.
func teste(){
var request = NSMutableURLRequest(URL: NSURL(string: "http://minhaurl/efetuarLogin.php?variavel=teste&get=valor")!)
var session = NSURLSession.sharedSession()
request.HTTPMethod = "POST"
var params = ["CPF":"00000000000", "senha":"12345678"] as Dictionary
var err: NSError?
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
var strData = NSString(data: data, encoding: NSUTF8StringEncoding)
var err: NSError?
var json = NSJSONSerialization.JSONObjectWithData(data, options: .MutableLeaves, error: &err) as NSDictionary
if((err) != nil) {
println(err!.localizedDescription)
} else {
println("JSON: \(json)")
}
})
task.resume()
}
In the PHP page I try to access the variables through $ _POST, $ _GET and even $ _REQUEST, only GET variables are received on the server.
Can anyone tell me what may be going wrong? Thanks in advance.