Php 带Mysql的swift 3
我正在尝试用mysql在swift3中注册 但是有点不对劲, 当我运行我的应用程序并使register return msg“某些字段为空”时 在php代码中:Php 带Mysql的swift 3,php,mysql,swift3,Php,Mysql,Swift3,我正在尝试用mysql在swift3中注册 但是有点不对劲, 当我运行我的应用程序并使register return msg“某些字段为空”时 在php代码中: $fullname = htmlentities($_REQUEST["fullname"]); $username = htmlentities($_REQUEST["username"]); $email = htmlentities($_REQUEST["email"]); $password = htmlentities($_R
$fullname = htmlentities($_REQUEST["fullname"]);
$username = htmlentities($_REQUEST["username"]);
$email = htmlentities($_REQUEST["email"]);
$password = htmlentities($_REQUEST["password"]);
$phone = htmlentities($_REQUEST["phone"])
swift代码:
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
我想你错过了这个
let task = session.dataTask(with: request) {data, response, error in
将
url
替换为request
请使用$\u POST
而不是$\u request
,这只是一个安全提示;第二,能否将$\u POST
记录在php文件中:文件内容('log.txt',json_encode($\u POST,json_PRETTY_PRINT))请使用$\u POST
而不是$\u REQUEST
,这只是一个安全提示;第二,能否将$\u POST
记录在php文件中:文件内容('log.txt',json_encode($\u POST,json_PRETTY_PRINT))代码>并告诉我们您得到了什么