Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response redirect 302 #14

Closed
aofeng2009 opened this issue May 15, 2020 · 5 comments
Closed

Response redirect 302 #14

aofeng2009 opened this issue May 15, 2020 · 5 comments

Comments

@aofeng2009
Copy link

当服务返回302重定向后,WKWebView 并不能拦截到响应,所以此时下发的cookie是没办法干预的。
不知道这里是否有优化的空间?

@karosLi
Copy link
Owner

karosLi commented May 18, 2020

image
你好,我刚才用服务器端302重定向后,是可以正确处理cookie的。

在发生302重定向时,会进入该方法,而且此时,WKWebView里的 Cookies.binarycookies 已经持久化了响应头里的 cookie。然后此时,可以在下面的方法里可把WKWebView里的 Cookies.binarycookies 同步给 NSHTTPCookieStorage。

  • (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
    }

@aofeng2009
Copy link
Author

aofeng2009 commented May 18, 2020

image
你好,我刚才用服务器端302重定向后,是可以正确处理cookie的。

在发生302重定向时,会进入该方法,而且此时,WKWebView里的 Cookies.binarycookies 已经持久化了响应头里的 cookie。然后此时,可以在下面的方法里可把WKWebView里的 Cookies.binarycookies 同步给 NSHTTPCookieStorage。

  • (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
    }

你可试试你的demo,在KKWebView 的 decidePolicyForNavigationResponse处设置一个端点。打印下response,那个response对应的url是index的不是 index302的。

@karosLi
Copy link
Owner

karosLi commented May 19, 2020

这个WebView自己的机制,遇到302,重新进入decidePolicyForNavigationAction方法,decidePolicyForNavigationResponse 只会接收重定向后的 index

@aofeng2009
Copy link
Author

@karosLi 是的,不过有的服务是在302响应的同时,下发cookie。暂不关心跳转之后(index)的response,302对应的response我们还是没办法处理的。

@karosLi
Copy link
Owner

karosLi commented May 19, 2020

嗯,这种目前还处理不了,最好还是让index response的cookie包含302 response 的cookie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants