joethemow joethemow - 1 year ago 81
iOS Question

Nothing is getting posted to my php script

I have a php script on my server and I am trying to post data from my ios app, but when I print the post variables I get a nil. Any idea why that is?


let url: NSURL = NSURL(string: "")!
let request:NSMutableURLRequest = NSMutableURLRequest(url: url as URL)
let bodyData = "username=\(username.text)&password=\(password.text)"
request.httpMethod = "POST"
request.httpBody = String.Encoding.utf8);
request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue.main)
(response, data, error) in
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("response \(responseString)")



print_r($_POST); //prints: ([username] => xxxxxx [password] => yyyyyy)

Answer Source

May be it is the problem of echo($postUser); just use json_encode($postUser);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download