当我运行此代码时,所有代码都得到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,响应状态:端点http://localhost:5000/aktionsdaten/temperatur/jQNguWfyGowlS3QoOI2vTWcX71RUjsZg处为500 错误1,响应状态:端点http://localhost:5000/aktionsdaten/light/jQNguWfyGowlS3QoOI2vTWcX71RUjsZg处为500 错误1,响应状态:endipont http://localhost:5000/aktionsdaten/feuchtigkeit/jQNguWfyGowlS3QoOI2vTWcX71RUjsZg为500 错误1,响应状态:endipont http://localhost:5000/aktionsdaten/ph/jQNguWfyGowlS3QoOI2vTWcX71RUjsZg
为500
当我只运行一个请求时,我得到:
example success