0
サーバーにデータを送信しようとしましたが、コードを実行するたびに空の行がデータベースに追加され、xcodeに「文字1の前後で値が無効です」というエラーが表示されます。 UserInfo = {文字1.周りNSDebugDescription =無効な値}文字の前後で値が無効
@IBAction func submitButton(_ sender: Any) {
let parameters = ["paramname": "abc",
"paramemail": "[email protected]",
"parammobile": "1234567890",
"paramroomno": "402",
"paramtime": "9",
"paramsno": "137865",
"paramcomplaint": "ios appp check",
"paramblock": "CSE",
"paramtype": "server"] as Dictionary< String, String>
guard let url=URL(string:"http://uietcloud.puchd.ac.in/mail/submit.php")
else {
return
}
let session = URLSession.shared
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Value", forHTTPHeaderField: "Key")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) else {
return}
request.httpBody = httpBody
request.addValue("application/json", forHTTPHeaderField: "Accept")
session.dataTask(with: request) { (data, response, error) in
if let data = data
{
do
{
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
print(json)
print("not an error")
}
catch{
print(error)
print("this is an error")
}
}
}
.resume()
}
まだ動作していない、私は行を更新しました:ガードlet httpBody = try? JSONSerialization.data(withJSONObject:パラメータ、オプション:[])else { return} – hammad119