[英]Alamofire post request FAILURE error
我目前正在與Stripe合作,嘗試使用Alamofire和Heroku將Stripe令牌發送到我的后端。 我的代碼如下:
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打印為FAILURE(參見上面的第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
關於為什么我可能會失敗的任何想法? 謝謝!
從您向我們展示的內容來看,很難說出問題出在哪里:)
但是,這一行:
Optional(<NSHTTPURLResponse: 0x600000425400> { URL: https://limitless-fjord-73001.herokuapp.com/charge.php } { status code: 500, headers {
更具體地說,這部分內容:
status code: 500, headers
似乎表明您從后端收到了錯誤代碼500,這意味着存在某種服務器端錯誤。
因此,您的服務器上是否有一個日志文件可以查看並查看是否告訴您某些信息?
希望能給您一些幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.