我正在使用 Alamofire 发出从在 Heroku 上运行的 Rails 应用程序返回 JSON 的 HTTP 请求。
进行 HTTP GET 调用时,我在客户端收到此 NSError:
Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed
(NSURLErrorDomain error -1005.)
" UserInfo=0x1700e6a00
{
NSErrorFailingURLStringKey=https://********.herokuapp.com/api/workouts.json,
NSErrorFailingURLKey=https://********.herokuapp.com/api/workouts.json,
_kCFStreamErrorDomainKey=4,
_kCFStreamErrorCodeKey=-4,
NSUnderlyingError=0x17025c920 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"
}
错误 -1005 是 kCFURLErrorNetworkConnectionLost
。
在 Heroku 日志中我得到:
heroku[router]: sock=client at=error code=H18
desc="Request Interrupted"
method=GET path="/api/workouts.json"
host=********.herokuapp.com
request_id=826f4f74-a497-4462-a70b-cc5d352ef7b4
fwd="162.246.8.76"
dyno=web.1 connect=1ms service=0ms status=503 bytes=0
2015-01-15T03:30:15.428551+00:00 app[web.1]:
Started GET "/api/workouts.json"
for 162.246.xxx.xxx at 2015-01-15 03:30:15 +0000
需要注意的重要部分是 sock=client
,这意味着请求在客户端请求时被中断。
sign_in
和 sign_up
等其他端点返回 200 OK
以及预期的负载。所以 Rails 应用程序正在其他端点上工作。
另外,请注意 curl 在命令行上按预期工作:
curl -X GET 'https://********.herokuapp.com/api/workouts.json?email=****&token=****'
最佳答案
也许它会对某人有所帮助:在我的例子中,我错误地发送了一个空字典作为参数:
var dictParams = [String: String]()
Manager.sharedInstance
.request(.GET, "\(K_API_MAIN_URL)\(k_API_XXXXXX)?access_token=\(strToken)", parameters: dictParams, encoding: .JSON)
解决方案是发送 nil 而不是上面的 dictParams。
Manager.sharedInstance
.request(.GET, "\(K_API_MAIN_URL)\(k_API_XXXXXX)?access_token=\(strToken)", parameters: nil, encoding: .JSON)
关于ios - 使用 Alamofire 时出现 Heroku "Request Interrupted"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27956595/