2
我目前有條紋的工作,試圖條紋令牌發送到使用Alamofire和Heroku上我的後端。我的代碼如下:Alamofire POST請求失敗錯誤
func postStripeToken(_ token: STPToken) {
let URL = "https://limitless-fjord-73001.herokuapp.com/charge.php"
let params = ["stripeToken": token.tokenId,
"amount": Int(self.amountTextField.text!)!,
"currency": "usd"] as [String : Any]
Alamofire.request(URL, method: .post, parameters: params)
.responseJSON { response in
print(response.request as Any) // original URL request
print(response.response as Any) // URL response
print(response.data as Any) // server data
print(response.result as Any) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
}
我遇到的問題是,我的response.result作爲故障打印(見上文第13行)。一切似乎是印刷精美,包括令牌和response.request線,response.response和response.data:
Optional(https://limitless-fjord-73001.herokuapp.com/charge.php)
Optional(<NSHTTPURLResponse: 0x600000425400> { URL: https://limitless-fjord-73001.herokuapp.com/charge.php } { status code: 500, headers {
Connection = "keep-alive";
"Content-Length" = 0;
"Content-Type" = "text/html; charset=UTF-8";
Date = "Mon, 29 May 2017 05:58:35 GMT";
Server = Apache;
Via = "1.1 vegur";
} })
Optional(0 bytes)
FAILURE
爲什麼我可以得到一個失敗的任何想法?謝謝!
謝謝你的回覆!我檢查了日誌,結果發現我在後端編寫的一些PHP代碼有語法錯誤。非常感激。 –
@ M.Ying很高興你解決了它。隨時upvote答案或標記爲正確的,如果它幫助你:) – pbodsk