先说下项目需求:自己写了个淘宝登录界面,点击登录后会调用使用okhttp post登录淘宝,okhttp的onResponse方法返回一个登录后html网页,将返回的网页显示到webview。
遇到的问题:okhttp post登录淘宝成功,通过okhttp的cookiejar获取登录后的cookie,同步到webview失效,webview显示的还是登录的网页。
下面记录一下我的实现过程:
1:自己写的一个简单界面
![](https://upload-images.jianshu.io/upload_images/12000114-be70097b283e3aed.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2:点击登录后使用okhttp post登录淘宝,看下代码
![](https://upload-images.jianshu.io/upload_images/12000114-55de23e46a7c3640.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3:通过onResponse方法判断是否登录成功,交给Hanlder处理
![](https://upload-images.jianshu.io/upload_images/12000114-1363dbf2208bb3e3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4:Handler处理
![](https://upload-images.jianshu.io/upload_images/12000114-f4ccce1e956db6b5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
5:syncCookie()方法
![](https://upload-images.jianshu.io/upload_images/12000114-a384eee5fc83f928.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
两个星期了,还是无解,依旧同步不来Cookie,要显示网页就必须要使用WebView,但Webview的同步Cookie不好驾驭
未完带续。。。
欢迎大家一起交流,可以私信我,我的QQ:1214585092