Post

Replies

Boosts

Views

Activity

WKWebView using URLRequest with POST results in nil body
Hello,I'm writing an application that uses WKWebView on iOS 11.4.We initiate the webview by loading a remote URL. Then the user navigates normally, but when we are about to load a certain url (as detected by the delegate method "func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {we must make a submit to a given url (basically we must authenticate the user with a pair of credentials he has stored in the App beforehand).we tried this 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: "&") }But then we check the same request in the delegate methodfunc webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { print("BODY", navigationAction.request.httpBody)and the body is null.In fact the request fails and we get an error in the WKWebView page.Is this still the bug as inhttps://forums.developer.apple.com/thread/18952or is it something I'm doing wrong?ThanksW
8
0
26k
Sep ’18