gpt4 book ai didi

ios - Swift 2.0 POST 主体为空

转载 作者:行者123 更新时间:2023-11-30 14:13:26 25 4
gpt4 key购买 nike

使用数据包分析器,我发现我的 HTTP 正文为空。有什么原因导致我的参数没有在 POST 请求中发送吗?

let request = NSMutableURLRequest(URL: NSURL(string:"SERVERURL")!)
request.HTTPMethod = "POST"

do {
let params = ["returnInt":"5"] as Dictionary<String,String>
request.HTTPBody = try NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions.PrettyPrinted)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
} catch {
//Do nothing
}
let task = NSURLSession.sharedSession().dataTaskWithRequest(request){
data, response, error in

if error != nil{
print("error=\(error)")
return
}
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("\(responseString)")
}
task!.resume()

最佳答案

正如我在 Playground 中使用 println() 看到的那样,request.HTTPBody 不是nil。另外,我的分析器也显示不nil:

enter image description here

关于ios - Swift 2.0 POST 主体为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31499870/

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