1

我正在开发一个 iOS 应用程序并使用 Deployd 作为后端。问题是当我使用 sid cookie 向用户/我发送 GET 请求以识别我的会话时,即使用户已登录,它也会返回 204-no 内容。我期待一些数据作为回报。

Xcode 控制台输出:

<NSHTTPURLResponse: 0x136ed2e00> { URL: http://xxxxxxxxxxxxxxx:2403/users/me?sid=3f53dd6c10...9fc4a00 } { status code: 204, headers {
"Cache-Control" = "no-cache, no-store, must-revalidate";
Connection = "keep-alive";
Date = "Sat, 16 Jan 2016 18:55:16 GMT";
Expires = 0;
Pragma = "no-cache"; } }
4

1 回答 1

1

所以我将 SID 作为参数发送,这是不正确的。部署需要一个“屏障令牌”。

SWIFT代码:

let url = NSURL(string: "http:/xxxxxxxxxxxxxxxx.com:2403/users/me")
            let request = NSMutableURLRequest(URL: url!)
            request.HTTPMethod = "GET"
            request.setValue( "Bearer \(token!)", forHTTPHeaderField: "Authorization")

            NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.currentQueue()!) { response, maybeData, error in
                if let data = maybeData {
                    let contents = NSString(data:data, encoding:NSUTF8StringEncoding)
                    print(contents!, "bitch")
                } else {
                    print(error!.localizedDescription)
                }
            }
于 2016-01-18T09:09:59.160 回答