linux - 涉及 Swift 3.0.2 的重定向 URL 的问题

标签 linux swift ibm-cloud foundation kitura

我正在尝试加载重定向的 URL。它在 Mac OS 上运行良好,但是当我使用 Kitura 1.4 服务器、Swift 3.0.2 将它推送到 Bluemix 时,出现以下加载错误:
操作无法完成

这是我的相关代码:

…
let gShort = URL(string: "https://blabla.bl/blabla")! // Because SO don't want shortened urls in the example
var request = URLRequest(url: gShort, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 3)
request.httpMethod = "HEAD"

let dataTask = URLSession(configuration: URLSessionConfiguration.default)
    .dataTask(with: request, completionHandler: { data, loadResponse, error in
        guard let redirected = loadResponse?.url else {
            …
        }
    })

dataTask.resume()

我实际上并不关心响应;我只想要重定向的 URL。这就是为什么我使用“HEAD”,但“GET”具有相同的行为,即在 Mac OS 上工作正常但在 Bluemix 上不起作用。

我还没有找到解决方法。我不知道这是 Swift/Foundation 或 Kitura 中的错误,还是 Bluemix 阻止了重定向的 URL。

有人知道怎么解决吗?

最佳答案

(这可能是评论,但我的声望还不够!)

是的,重定向支持尚未在 Swift Foundation 中实现。很久以前打开了一个相关的错误报告 - https://bugs.swift.org/browse/SR-2678

关于linux - 涉及 Swift 3.0.2 的重定向 URL 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41308563/

相关文章:

php - 从 PHP 中执行我的程序?

json - 将 NSData 对象转换为 NSDictionary 时出现问题

python - 使用 raspberry-pi3 和 Bluemix 的 IoT 项目。错误: TwilioRestClient has been removed from this version of the library

service - Bluemix 服务端点是否可公开访问?

ibm-cloud - 在 Cloudant 中轮询更改源时,我是否可以获得所有修订?

c++ - 我如何在 monodevelop (C++) 中链接 SDL 和 GL

linux - 可以使用 Wget 指定要下载的文件内容类型吗?

linux - "Command not found"当输出存储在变量中时管道变量被剪切

iOS Swift 不支持的 URL

swift - 在 Swift 中使用 slider 控制 ciFilter