Web视图未加载url请求,URL显示为空

问题描述 投票:0回答:1

我想使用linkedin授权URL加载Web视图,但是在未创建加载URL之前声明它为nil并且Web视图未显示任何特定页面。这是传递给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)
ios swift linkedin
1个回答
0
投票

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

您可以使用它来编码那些混乱的字符:

let newURL = YOUR_URL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: newURL)
© www.soinside.com 2019 - 2024. All rights reserved.