【问题标题】:how to pass parameters in body when sending request with Alamofire in Swift在 Swift 中使用 Alamofire 发送请求时如何在正文中传递参数
【发布时间】:2022-01-07 17:57:53
【问题描述】:

我有一个将我的应用程序数据保存在 MongoDB 中的 api (nodejs)。但是当我发送请求时,节点会抛出一个错误,指出scoreundefined

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'score' of undefined

当 Xcode 发送请求时,应用程序工作了大约 30 秒,然后崩溃和 Xcode 日志:"The request timed out."

这是我的 Swift 代码:

let parameters = ["score": scoreBoard]
print(parameters)
AF.request("http://localhost:4000/update/score", method: .post, parameters: parameters).responseDecodable(of: [jsonData].self) {response in
                      let json = JSON(response.data!)[0]["score"]
                      scoreBoard = json.rawString()!
                }

【问题讨论】:

    标签: ios swift dictionary swiftui alamofire


    【解决方案1】:

    问题出在 Node 上,我没有使用正文解析器。当我包含一个正文解析器时,它就能够从正文中检索数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-15
      • 2019-09-15
      • 2020-11-09
      • 2017-12-03
      • 1970-01-01
      • 2017-05-04
      • 2017-11-16
      相关资源
      最近更新 更多