gpt4 book ai didi

swift - 完美,快速,从处理程序中的请求获取服务器地址

转载 作者:行者123 更新时间:2023-11-30 12:35:16 28 4
gpt4 key购买 nike

在请求处理程序中,处理例如获取 https://example.com/collections/1或 POSThttp://0.0.0.0:8080/collections 如何获取服务器地址 https://example.comhttp://0.0.0.0:8080分别?

目前我正在像这样构建它

 var url = "\(httpPrefix)\(server.serverAddress)"
if server.serverPort != 443 { url += ":\(server.serverPort)" }

其中 httpPrefix 是:

let httpPrefix = isLinux ? "https://" : "http://"

但感觉还有更好的方法......

最佳答案

我发现 host header 将包含 example.com0.0.0.0:8080,具体取决于服务器。

所以下面的结果正是我需要的结果。 httpScheme 仍然是硬编码的(这是我不喜欢的,但还没有看到其他选项)。

httpScheme + request.header(.host)!

我正在强制展开,因为我观察到主机 header 始终存在。

关于swift - 完美,快速,从处理程序中的请求获取服务器地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42958284/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com