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