let Url = String(format: "http://url/ios.php")
guard let serviceUrl = URL(string: Url) else { return }
let parameterDictionary :[String:String] = ["Episodes" : "http://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()
}
我收到错误
Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.}
不确定我是否正确发送数据,我认为我设置httpbody incorectly
我甚至试过json request.setValue(“application / json”,forHTTPHeaderField:“Content-Type”)后卫让httpBody =试试? JSONSerialization.data(withJSONObject:parameterDictionary,options:[])else
1 回答
Swift 3,试试这个,删除 responseHandler 参数和任何其他如果你的代码中没有使用它