0

I am loading a WKWebview and setting up a cookie. The server is receiving it correctly.

The web page that is loaded is making more calls to the server to load other resources: css, js, etc.

How to make sure the cookie I set in the first call is used for all the subsequent calls?

Here is a part of the code:

let requestUrl = URL(string: url)
var request = URLRequest(url: requestUrl!)
let cookie = “cookieName=" + cookieValue
request.addValue(cookie, forHTTPHeaderField: "Cookie")


let webConfiguration = WKWebViewConfiguration()
wkWebView = WKWebView(frame: .zero, configuration: webConfiguration)
self.view.addSubview(wkWebView)

wkWebView.load(request)
dragos
  • 300
  • 1
  • 4
  • 12

1 Answers1

0

Actually, the problem was from the server.

When the web view is loading and URL, it is sending a request to the server including the cookies I've sent. The server is returning a response and it is including a list of cookies. These cookies are used for the subsequent requests to the server for css or js files.

In my case, the server was not returning the correct cookies so the web view was not including any cookie to the calls to css and js files.

dragos
  • 300
  • 1
  • 4
  • 12