登录页面的URL会话问题

问题描述 投票:0回答:1

我正在尝试为Swift 5的登录页面创建一个登录系统。我的php文件运行正常,但是我的URLSession遇到问题。我正在考虑为此使用Alamofire,因为它适用于我的登录页面。下面的代码在let task = session.dataTask(with: request, completionHandler: { data, response, error in

中出现错误
} else {

        //Shortcuts
        let username = usernameTextfield.text!.lowercased()
        let password = passwordTextField.text

        //send request to sql db
        let url = URL(string: "http://localhost/myApp/login.php")!
        let request = NSMutableURLRequest(url: url)
        request.httpMethod = "POST"
        let body = "username=\(String(describing: username))&password\(String(describing: password))"
        let session = URLSession.shared
        request.httpBody = body.data(using: .utf8, allowLossyConversion: true)


        let task = session.dataTask(with: request, completionHandler: { data, response, error in

            // Do something...
        })
swift alamofire
1个回答
0
投票

错误可能是由于使用@NicolasElPapu指出的NSMutableURLRequest。请参阅this SO帖子。

© www.soinside.com 2019 - 2024. All rights reserved.