WKWebView ajax請求Cookie丟失

image.png

使用 Charles 抓包(Mac推薦Charles

發現H5裏面 ajax請求失敗302,這可能Cookie丟失或Cookie不相同了

原因是 WKWebView 請求攜帶的 Cookie 的 Secure 屬性不齊全

在後面拼接完整 Cookie 的 Secure 屬性 cookie、 path、domain Document.cookie - Web APIs | MDN

NSString *jsStringCookie= [NSString stringWithFormat:@"document.cookie='%@=%@; path=%@; domain=%@';", cookie.Name, cookie.Value, cookie.Path, cookie.Domain];
NSString *headerStringCookie= [NSString stringWithFormat:@"'%@=%@; path=%@; domain=%@';", cookie.Name, cookie.Value, cookie.Path, cookie.Domain];
  • WKWebview 其他問題可以參考以下文章

WKWebView那些坑- 騰訊Bugly iOS 中 UIWebView 與 WKWebView、JavaScript 與 OC 交互、Cookie 管理看我就夠(中)

Can I set the cookies to be used by a WKWebView?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章