使用基本身份验证加载会话Swift

时间:2018-06-08 19:05:26

标签: swift session basic-authentication wkwebview

当我在WebView上加载请求时,它未登录并重定向到登录页面。我在这里做错了什么 - 我几乎看过那里的例子而且他们都不能工作。

var request = NSMutableURLRequest(url: NSURL(string: "https://moyer.ureward.me/rewards")! as URL)
request.httpMethod = "POST" 
request.setValue("Basic d2lsbGFiYXR0QGdtYWlsLmNvbTpTdzMzdHlwMTM=", forHTTPHeaderField: "Authorization")

let session = URLSession.shared

let task = session.dataTask(with: request as URLRequest){ (data, response, error) in
    if (error != nil) {
        print(error as Any)
    } else {
        print(String(data: data!, encoding: .utf8) as Any)
    }
}

task.resume()

WebView.load(request as URLRequest)

0 个答案:

没有答案