webview 监听及获取cookie

 

 

https://www.cnblogs.com/pjl43/p/9866753.html

https://www.jianshu.com/p/55092eb06c17

 

requests:

 https://stackoverflow.com/questions/53101858/handling-cookies-in-flutter

 

heck out requests, a flutter library to help with modern RESTful http requests (basic cookies support and json)

  • as of now, it uses shared_preferences which is not the best practice (security-wise) to store sensitive data (session-ids etc) Issue #1

pubspec.yaml

dependencies:
  requests: ^1.0.0

Usage:

import 'package:requests/requests.dart';

// ...

// this will persist cookies
await Requests.post("https://example.com/api/v1/login", body: {"username":"...", "password":"..."} ); 

// this will re-use the persisted cookies
dynamic data = await Requests.get("https://example.com/api/v1/stuff", json: true); 

  

 

https://pub.dartlang.org/packages/dio#cookie-manager

 

 

https://github.com/fluttercommunity/flutter_webview_plugin/pull/51

Unfortunately, I was not considering operating LocalStorage from outside WebView.

Although I tried a little investigation,
there seems to be a case in which execution of evalJavascript or access to LocalStorage can not be performed normally due to the timing of WebView startup, the timing of page loading, and so on.

You may be able to avoid it by waiting until the first page loading is completed and then accessing LocalStorage with evalJavascript.

like this.

// On urlChanged stream
StreamSubscription<WebViewStateChanged> _onStateChanged;
_onStateChanged = flutterWebviewPlugin.onStateChanged.listen((WebViewStateChanged state) { if (mounted) { if (state.type == WebViewState.finishLoad) { flutterWebviewPlugin.evalJavascript( "window.localStorage.setItem('LOCAL_STORAGE','SOMETOKEN');" + "document.getElementById('showLocalStorageBtn').click();" ); } } });

i hope you will find it helpful.

 

转载于:https://www.cnblogs.com/pythonClub/p/10675893.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值