WKWebView无法携带302重定向的Cookie [英] WKWebView can't carry cookie for 302 redirect

查看:561
本文介绍了WKWebView无法携带302重定向的Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调用loadRequest()函数加载页面之前在请求标头中设置了cookie。我还使用document.cookie()通过WKUserScript根据[ WKWebView Cookies 设置cookie。但是,我发现如果发生302重定向,请求可能会因Cookie丢失而失败。例如, http:// A 的请求重定向到 http:// B ,我可以通过操作请求为 http:// A 的请求设置Cookie头并使用WKUserScript,但是这两种方式无法为 http:// B 的请求设置cookie,因此< a href = http:// B rel = nofollow noreferrer> http:// B 可能会失败。这种情况在ios8中的发生频率要高于ios9。有人有解决方法吗?

I set cookie in request header before I call loadRequest() function to load a page. I also use document.cookie() to set cookie by WKUserScript according to [WKWebView Cookies. However, I find that if a 302 redirection occurs, request may fail for loss of cookie. For example, the request of http://A redirect to http://B, I could set cookie for request of http://A by operating request head and using WKUserScript, but these two ways can not set cookie for request of http://B, so the 302 request of http://B may fail. This situation occurs in ios8 more frequently than ios9. Does anybody have a workaround?

推荐答案

在iOS中设置cookie的解决方法,请检查我的答案。您必须同时在request和wkuserscript中设置cookie。否则,它将失败一次并在第二次运行中成功,

workaround for set cookies in iOS please check my answer. You must set cookies both in request and wkuserscript same time. otherwise it fail one time and sucess in 2nd run,

可以设置WKWebView使用的cookie吗?

这篇关于WKWebView无法携带302重定向的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆