2

I am trying to send cookies with a URLRequest to a WKWebView in my phone app. This part requires the user to be logged in, therefore I must set my cookies. When I check safari inspection I saw that my cookies are not set and I get redirected to my login page. Here is my code snippet.

    var request = URLRequest(url: url)
    request.httpMethod = "GET"
    request.setValue("cookie1=\(val1);cookie2=\(val2);", forHTTPHeaderField: "Cookie")
    request.httpShouldHandleCookies = true
    webView.loadRequest(request)
BearBearBear
  • 109
  • 3
  • 9
  • Better check [this thread](https://stackoverflow.com/q/26573137/6541007). – OOPer Aug 10 '18 at 20:14
  • I have attempted Mattr's suggestion using HTTPCookieStorage to set cookies before but it did not work for me. I decided to see if I can just directly set the cookies in the header and see if that would work at all – BearBearBear Aug 10 '18 at 20:21
  • The thread shows more ways to set cookies than I can think of. You should better check what is special on your server side. Anyway seems I cannot be help to solve your issue. Hope you can solve it soon. Please share your experience after you solve it. – OOPer Aug 10 '18 at 20:30
  • Possible duplicate of [Can I set the cookies to be used by a WKWebView?](https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview) – adev Aug 11 '18 at 02:20

0 Answers0