抱歉,我的英语很弱,我尝试了多种类型的解决方案,但无法Xcode 11.2.1
使用swift 5
我试试这个
var urlRequest = URLRequest(url: URL(string: "https://xxxxxx/login")!)
urlRequest.httpMethod = "POST"
let params = [
"username": SessionManager.shared.username!,
"password": SessionManager.shared.password!,
"vhost": "standard"
]
let postString = self.getPostString(params: params)
urlRequest.httpBody = postString.data(using: .utf8)
webView.load(urlRequest)
...
//helper method to build url form request
func getPostString(params:[String:String]) -> String
{
var data = [String]()
for(key, value) in params
{
data.append(key + "=\(value)")
}
return data.map { String($0) }.joined(separator: "&")
}
和这个
并尝试在我的代码中添加以下行
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
但不工作我触发请求,因为不工作WKWebView
屏幕是打开但不是加载请求。如果我没有设置navigationDelegate并打开正常URL
,那么它完全可以
工作帮我。提前致谢URL
URL
WKWebView