gpt4 book ai didi

ios - 从通过 WebSocket 发送的 JSON 数据在 Swift 中发送 POST 请求

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

我正在尝试根据通过 WebSocket 发送的质询在 Swift 2.2 中发送 POST 请求。我当前的代码可以找到here .在 respondToChallenge 函数中,我需要执行通过 WebSocket 发送的 JSON

这是一个挑战示例:

[{
"meth": "POST",
"host": "https://openpokemap.pw"
"cont": "application/x-www-form-urlencoded"
"user": "Firefox 42...."
"data": "sjdbsjkbd" //Base64 encoded byte array
}]

而且我还需要通过 JSON 中声明的“主机”发布状态代码 200。

谢谢,请放轻松,这是我的第一篇文章。

最佳答案

从 JSON 响应中,您可以很容易地在序列化后返回主机。

do {
let dict = try NSJSONSerialization.JSONObjectWithData(challenge.dataUsingEncoding(NSUTF8StringEncoding)) as! [String: AnyObject]
let host = response["host"] as? String
print("Host: \(host)")
} catch {
print("JSON error: \(error")
}

从那里,您可以使用 NSURLSession发出 POST 请求。

关于ios - 从通过 WebSocket 发送的 JSON 数据在 Swift 中发送 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39272550/

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