ios - 执行多个 Alamofire 请求时出现错误 (500)
问题描述
当我运行这段代码时,我得到了 500 分。但是,如果我只运行一个请求,它工作得很好
我在操场上的代码:
import UIKit
import Alamofire
var url : String = "http://localhost:5000/"
var fieldid: String = "jQNguWfyGowlS3QoOI2vTWcX71RUjsZg"
var resreturn: [String: [Double]] = ["temperature":[], "humidity":[], "ph":[], "light":[]]
var resresreturn: [[String: [Double]]] = []
let dispatch2 = DispatchGroup()
dispatch2.enter()
resresreturn = []
let dispatch = DispatchGroup()
dispatch.enter()
dispatch.enter()
let myurltemp = url + "aktionsdaten/temperatur/" + fieldid
Alamofire.request(myurltemp, method: .get).responseJSON{ response1 in
if let status = response1.response?.statusCode {
switch(status){
case 201, 200:
print("example success")
default:
print("error 1 with response status: \(status) at endpont \(myurltemp)")
return
}
}
if let result = response1.result.value {
resreturn["ph"] = result as! NSArray as? [Double] ?? [0.0,0.0]
dispatch.leave()
}
}
dispatch.enter()
let myurllight = url + "aktionsdaten/light/" + fieldid
Alamofire.request(myurllight, method: .get).responseJSON{ response2 in
if let status = response2.response?.statusCode {
switch(status){
case 201, 200:
print("example success")
default:
print("error 1 with response status: \(status) at endpont \(myurllight)")
return
}
}
if let result = response2.result.value {
resreturn["ph"] = result as! NSArray as? [Double] ?? [0.0,0.0]
dispatch.leave()
}
}
dispatch.enter()
let myurlakt = url + "aktionsdaten/ph/" + fieldid
Alamofire.request(myurlakt, method: .get).responseJSON{ response3 in
if let status = response3.response?.statusCode {
switch(status){
case 201, 200:
print("example success")
default:
print("error 1 with response status: \(status) at endpont \(myurlakt)")
return
}
}
if let result = response3.result.value {
resreturn["ph"] = result as! NSArray as? [Double] ?? [0.0,0.0]
dispatch.leave()
}
}
let myurlhum = url + "aktionsdaten/feuchtigkeit/" + fieldid
Alamofire.request(myurlhum, method: .get).responseJSON{ response4 in
if let status = response4.response?.statusCode {
switch(status){
case 201, 200:
print("example success")
default:
print("error 1 with response status: \(status) at endpont \(myurlhum)")
return
}
}
if let result = response4.result.value {
resreturn["ph"] = result as! NSArray as? [Double] ?? [0.0,0.0]
dispatch.leave()
}
}
dispatch.notify(queue: .main, execute: {
resresreturn.append(resreturn)
dispatch2.leave()
})
错误日志:
错误 1 响应状态:500 在 endpiont http://localhost:5000/aktionsdaten/temperatur/jQNguWfyGowlS3QoOI2vTWcX71RUjsZg 错误1 响应状态:500 在 endpiont http://localhost:5000/aktionsdaten/light/jQNguWfyGowlS3QoOI2vTWcX71RUjsZg 错误1 响应状态: 500 在 endipont http://localhost:5000/aktionsdaten/feuchtigkeit/jQNguWfyGowlS3QoOI2vTWcX71RUjsZg 错误 1 响应状态:500 在 endipont http://localhost:5000/aktionsdaten/ph/jQNguWfyGowlS3QoOI2vTWcX71RUjsZg
当我只运行一个请求时,我得到:
example success
解决方案
推荐阅读
- css - 如何让到处下雨?
- c++ - 创建从 Variadic Template Pack 派生的类型的元组
- r - 将向量重命名为向量名称和 df 名称的混合
- python - Pandas 的条件平均值
- c# - C# 后台工作人员 - 我应该同时使用多少?
- c# - 使用 Enumerable.Repeat 进行容量列表初始化的问题
- python - 自动将 `stackedWidget` 页面的高度调整为放置在其上的小部件的高度
- flutter - 如何制作一个看起来像这样在颤动中弹出的按钮
- scala - 使用 Spark ML 计算 PCA 时出现 IllegalArgumentException
- python - 请求非常慢,有时会返回错误