zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    Docker用途 & 和tomcat的区别
    Ubuntu安装Redis
    Ubuntu查看和设置Root账户
    Oracle常用语句
    Redis知识总结
    Blazor学习笔记01: 使用BootstrapBlazor组件 创建一个具有单表维护功能的表格页面
    NET Core之积沙成塔01: 解决Visual Studio 2019 代码提示为英文
    MySQL系统自带的数据库information schema
    Windows安装mysql方法
    数据库之概念
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10675893.html
Copyright © 2011-2022 走看看