我正在尝试使用Alamofire
发布数组,但我收到此错误
请求失败并显示错误:错误Domain = com.alamofire.error Code = -6003“响应状态代码不可接受:403”UserInfo = {NSLocalizedFailureReason =响应状态代码不可接受:403}
我想在我的请求体中发送我的数组:
{
"ratings":[{
"safety_rating_id": 105
"schedule_job_id": 18,
"score": 9,
"submission_id": 27
},{
"safety_rating_id": 106
"schedule_job_id": 18,
"score": 10,
"submission_id": 27
}
这是我的代码
func getTaskDetails(onCompletion: () -> (), onError: ((NSError) -> ())? = nil) {
guard let token = Data.sharedInstance.token else { print("Empty token"); return }
let Auth_header = [
"Authorization" : token,
]
let parameters = [
"ratings" : [
[
"safety_rating_id" : 106,
"schedule_job_id" : 18,
"score" : 10,
"submission_id" : 27
],
[
"safety_rating_id" : 105,
"schedule_job_id" : 18,
"score" : 9,
"submission_id" : 27
]
]
]
Alamofire.request(.POST, Data.submitScoreEndpoint, headers: Auth_header, parameters: parameters)
.validate()
.responseJSON {
response in
switch response.result {
case .Success(let data):
let json = JSON(data)
print(json)
onCompletion()
case .Failure(let error):
print("Request failed with error: \(error)")
onError?(error)
}
}
}