我在使用Alamofire
發送請求時遇到問題。 我想發送POST請求的參數,但我不知道在哪裏把自定義頭像令牌。如何使用POST方法在swift中使用參數和標頭在Alamofire中發送請求
這裏是我的代碼:
let parameters = [
"id": ID,
"recipient_id" : recipientID,
"is_match" : "1"
]
Alamofire.request(.POST, Constants.baseURL + Constants.apiURL + Constants.accept, parameters: parameters, encoding: .JSON)
.validate()
.response { request, response, data, error in
print(request)
print(response)
print(data)
print(error)
}
.responseJSON { response in
switch response.result {
case .Success:
print("Approve Successful")
print("approve \(response)")
case .Failure(let error):
print(error)
}
}
順便說一句,我使用Alamofire 3.4
重複[here](http://stackoverflow.com/questions/32758053/swift-alamofire-add-custom-header-to-all-requests) –