【发布时间】:2015-11-21 03:24:20
【问题描述】:
我可以从产品路径中获取产品 ID,但在尝试向沙盒安排行程发布请求时出现此错误。试图弄清楚我在这里做错了什么。我添加了不记名令牌。我不确定它想要什么或缺少什么。
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x7f8c13939ed0 {NSErrorFailingURLStringKey=https://sandbox-api.uber.com/v1/requests, NSUnderlyingError=0x7f8c0ac78410 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)", NSErrorFailingURLKey=https://sandbox-api.uber.com/v1/requests}
func performPostUberRequest(url: NSURL, prodId: String) {
let params:[String: AnyObject] = [
"start_latitude" : "39.955715",
"start_longitude" : "-75.1680298",
"end_latitude" : "39.9542675",
"end_longitude" : "-75.1409609",
"product_id": prodId
]
var error: NSError?
var request: NSMutableURLRequest = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.addValue("Bearer \(uberToken)", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions.allZeros, error: &error)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()){
response, data, error in
if let error = error {
println(error)
} else if data != nil {
if let json: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as? NSDictionary {
println(json)
}
}
}
}
【问题讨论】:
-
返回给你的http代码是什么?
-
这是一个好问题,我怎样才能得到这些信息?我试图弄清楚如何查看整个原始请求/响应。
-
我还在“数据”中找到了更多信息,但响应为零。 {代码=未经授权; message = "缺少范围:请求"; }