Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用swift 3在后台打开url?_Ios_Swift - Fatal编程技术网

Ios 使用swift 3在后台打开url?

Ios 使用swift 3在后台打开url?,ios,swift,Ios,Swift,我想在后台打开一个url,用信息更新我的数据库, 但它不应该打开safari,因为客户不应该看到php链接 我很高兴能得到任何帮助, 我只需要帮助在后台打开URL我相信您正在寻找的是HTTP请求。这就是浏览器从网页中获取内容的方法。在iOS中,有许多方法可以对url执行HTTP请求。其中一种方法是使用URLSession类 let url = URL(string: "http://www.google.com/") //Or your URL var request = URLRequest(

我想在后台打开一个url,用信息更新我的数据库, 但它不应该打开safari,因为客户不应该看到php链接

我很高兴能得到任何帮助,
我只需要帮助在后台打开URL

我相信您正在寻找的是HTTP请求。这就是浏览器从网页中获取内容的方法。在iOS中,有许多方法可以对url执行HTTP请求。其中一种方法是使用URLSession类

let url = URL(string: "http://www.google.com/") //Or your URL
var request = URLRequest(url: url!)
request.httpMethod = "POST"
request.httpBody = "Data to send to your backend".data(using: .utf8)!

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if error != nil {
        //There was an error
    } else {
        //The HTTP request was successful
        print(String(data: data!, encoding: .utf8)!)
    }

}
task.resume()
这将在HTTP请求中将
httpBody
属性中的数据发送到后端