0

I am loading a url on webview, in which user will have to login. I am making a request by following way:

    let urlStr = "https://flex-showcase.bloxcms.com/business/guebert-food-and-family-a-must-for-sundays-in-april/article_94462124-fbd4-5d0b-9841-880d82844c05.html"
    var req = URLRequest(url: URL(string: urlStr)!)
    req.addValue("1", forHTTPHeaderField: "X-Townnews-Now-API-Version")
    let appdelegate =  UIApplication.shared.delegate as! AppDelegate
    let userAgent = appdelegate.appUserAgent
    appdelegate.webviewObj.customUserAgent = userAgent
    appdelegate.webviewObj.load(req)

after login we have seen that user session does not maintain properly. as we have seen that "X-Townnews-Now-API-Version" on all HTTP transactions is missing after login. Also I have observed that:

1) After reloading the webpage again every think works fine. 2) Also backend debugged that "login buttons are doing XHR, clicking on the sign-in button should have no bearing on HTTP requests. HTTP requests need to be intercepted at the webkit level and pass the right headers on all HTTP transactions."

  • Check my answer here https://stackoverflow.com/a/57975113/7551807 – Mussa Charles Sep 18 '19 at 07:06
  • Yes I am trying to intercept then find in decidePolicyFor delegate req.addValue("1", forHTTPHeaderField: "X-Townnews-Now-API-Version") is missing on all HTTP transactions. will you please help how can we maintain this in all transaction. – Fusioni Technologies Sep 18 '19 at 07:14
  • Please check this answer: https://stackoverflow.com/questions/28984212/how-to-add-http-headers-in-request-globally-for-ios-in-swift – Aamir Sep 18 '19 at 07:30
  • Possible duplicate of [Can't set headers on my WKWebView POST request](https://stackoverflow.com/questions/26253133/cant-set-headers-on-my-wkwebview-post-request) – Aamir Sep 18 '19 at 07:47
  • @Aamir we are able to see header in response but session does not maintain for first time whenever app launch – Fusioni Technologies Sep 18 '19 at 07:50
  • @FusioniTechnologies perhaps you can keep them in local storage/user defaults. – Aamir Sep 18 '19 at 07:51
  • @Aamir user login is handled by webview. whenever we request first time session is not maintained. after that if I hit the second request it is woking fine – Fusioni Technologies Sep 18 '19 at 07:53

0 Answers0