gpt4 book ai didi

php - 使用 Mysql 的 swift 3

转载 作者:行者123 更新时间:2023-11-30 22:09:11 24 4
gpt4 key购买 nike

我正在尝试使用 mysql 在 swift3 中进行注册但是有一点不对劲,当我运行我的应用程序并使注册返回消息“某些字段为空”

在 php 代码中:

$fullname = htmlentities($_REQUEST["fullname"]);
$username = htmlentities($_REQUEST["username"]);
$email = htmlentities($_REQUEST["email"]);
$password = htmlentities($_REQUEST["password"]);
$phone = htmlentities($_REQUEST["phone"])

快速代码:

let  config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let url = URL(string: "http://localhost/php/register.php?")
var request = URLRequest(url: url!)

request.httpMethod = "POST"

let body = "fullname=\(FirstName.text)%20\(LastName.text)&username=\(UserName.text)&email=\(Email.text)&password=\(Password.text)&phone=\(Phone.text)"

request.httpBody = body.data(using: String.Encoding.utf8)

let task = session.dataTask(with: url!) {data, response, error in

if error != nil {
print(error!.localizedDescription)

} else {

do {

if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]

{

print(json)

}

} catch {
print("error in JSONSerialization")
}

}

}
task.resume()

最佳答案

我想你错过了这个

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

url替换为request

关于php - 使用 Mysql 的 swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40683102/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com