[:en]Swift: HTTP with paraments[:]

[:en]HTTP

 func onlinecheckin(){
        
        if let user1 = username.text, pw1 = password.text {
            let user1B = user1.stringByReplacingOccurrencesOfString(" ", withString: "")
            let pw1B = pw1.stringByReplacingOccurrencesOfString(" ", withString: "")
            
            //Send user data to server side
            let myUrl = NSURL(string: "http://xxx.com/xxx/loginP.php")
            let request = NSMutableURLRequest(URL: myUrl!);
            request.HTTPMethod = "POST"
            let postString = "login_name=\(user1B)&login_pass=\(pw1B)&loginrecalled=\(logintime)&version=\(Version)&playstore=\(Playstore)"
            request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
            
            let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
                data, response, error in
                
                print("response =\(response)")
                
                if error != nil {
                    print("error=\(error)")
                    return
                }
                
                // Print out reponse body
                if let datadownload = data {
                    resultlogin = NSString(data: datadownload, encoding: NSUTF8StringEncoding)!.stringByReplacingOccurrencesOfString(" ", withString: "");
                    print("resultlogin:\(resultlogin)")
                }
                // Stop ActivityIndicator
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    if(resultlogin == "correct"){
                        userlogin = self.username.text!.stringByReplacingOccurrencesOfString(" ", withString: "")
                        print("userlogin:\(userlogin)")
                        self.downloaddatabasename()
                        self.downloadteachercourses()
                        self.downloaduserlevel()
                        if loginbuttonpressed == "reset" {
                            self.updatepassword()
                        }
                    }
                    else {
                        self.AlertMessage(wrongpasswordwarning);
                        
                    }
                    
                })
            }
            task.resume()
          
        }
    }

[:]

Print Friendly, PDF & Email
Scroll to Top