阅读背景:

如何使用Swift执行multipart / form-data post请求?

来源:互联网 
 let Url = String(format: "https://url/ios.php")
    guard let serviceUrl = URL(string: Url) else { return }
    let parameterDictionary :[String:String] = ["Episodes" : "https://url/anime/07-ghost.html"]
    var request = URLRequest(url: serviceUrl)
    request.httpMethod = "POST"
    request.setValue("multipart/form-data", forHTTPHeaderField: "Content-Type")
    request.httpBody = NSKeyedArchiver.archivedData(withRootObject: parameterDictionary)
    let session = URLSession.shared
    session.dataTask(with: request) { (data, response, error) in
        if let response = response {
            print(response)
        }
        if let data = data {
            do {
                let json = try JSONSerialization.jsonObject(with: data, options: [])
                print(json)
            }catch {
                print(error)
            }
        }
        }.resume()
    }
 let Url = String(format: "https://url/ios.php"



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: