gpt4 book ai didi

使用http请求快速发布到php

转载 作者:行者123 更新时间:2023-11-28 08:25:39 26 4
gpt4 key购买 nike

尝试将文本字段中输入的变量发送到 php 脚本以写入 sql 数据库。尝试使用 HTTP 请求

@IBAction func submit(_ sender: AnyObject) {

let requestURL = NSURL(string: "***************")

let request = NSMutableURLRequest(url: requestURL! as URL)

request.httpMethod = "POST"

let song=txt1.text!
let artist=txt2.text!
let album=txt3.text!
let year=txt4.text!
let genre=txt5.text!


let songPost = "song=" + (song as String)
let artistPost = "&artist=" + (artist as String)
let albumPost = "&album=" + (album as String)
let yearPost = "&year=" + (year as String)
let genrePost = "&genre=" + (genre as String)

request.httpBody = songPost.data(using: String.Encoding.utf8);
request.httpBody = artistPost.data(using: String.Encoding.utf8);
request.httpBody = albumPost.data(using: String.Encoding.utf8);
request.httpBody = yearPost.data(using: String.Encoding.utf8);
request.httpBody = genrePost.data(using: String.Encoding.utf8);
NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue.mainQueue)

我在阅读代码的最后一行时遇到错误:调用中参数“completion hander”缺少参数。

不知道这是什么意思。

最佳答案

这里的错误其实非常明显。此方法有一个名为 completionHandler 的第三个参数,您缺少它。 Documentation .用这个替换你的最后一行:

NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue.mainQueue)
{
response, data, error in
// handle response here
}

关于使用http请求快速发布到php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40093646/

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