gpt4 book ai didi

ios - Web View 未加载 url 请求且 URL 显示 nil

转载 作者:行者123 更新时间:2023-11-29 05:15:26 25 4
gpt4 key购买 nike

我想使用 linkedin 授权 url 加载 Web View ,但在加载 url 之前未创建,说明它为 nil,并且 Web View 不显示任何特定页面。这是传递给 URLRequest 的 url 字符串。 https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id= ******&redirect_uri=****&state=linkedin1575812567&scope=r_liteprofile

下面提到的是代码。

    let responseType = "code"
let state = "linkedin\(Int(NSDate().timeIntervalSince1970))"

var authorizationURL = "\(authorizationEndPoint)?"
authorizationURL += "response_type=\(responseType)&"
authorizationURL += "client_id=\(linkedInConfig.linkedInKey)&"
authorizationURL += "redirect_uri=\(linkedInConfig.redirectURL)&"
authorizationURL += "state=\(state)&"
authorizationURL += "scope=\(scope)"


print(authorizationURL)
let url = URL(string: authorizationURL)

let request = URLRequest(url: url!)
webView.load(request)

最佳答案

URL 只能包含特定的字符集。使用其他字符可能会导致此类错误。或者甚至允许的字符有时也会导致这种情况,例如“&”用作分隔符,不能直接在 URL 查询参数值中使用。

您可以使用它来编码那些困惑的字符:

let newURL = YOUR_URL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: newURL)

关于ios - Web View 未加载 url 请求且 URL 显示 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59236119/

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