dio icon indicating copy to clipboard operation
dio copied to clipboard

login a website failed via cookie_manager but python code ok

Open 276562578 opened this issue 3 years ago • 0 comments

New Issue Checklist

  • [x] I have searched for a similar issue in the project and found none

Issue Info

Issue Description and Steps

The python code

>>> import requests
>>> import bs4
>>> webVPNUrl = "https://webvpn.jlu.edu.cn/login"
>>> webVPNUrl_login = "https://webvpn.jlu.edu.cn/do-login"
>>> soup=bs4.BeautifulSoup(s.get(webVPNUrl).content)
>>> captcha_id=soup.find_all("input")[6].attrs["value"]
>>> login=s.post(webVPNUrl_login,data={
...       "auth_type": "local",
...       "username": username,
...       "sms_code": "",
...       "password": password,
...       "captcha": "",
...       "needCaptcha": "false",
...       "captcha_id": captcha_id
...     })
>>> print(s.get("https://webvpn.jlu.edu.cn").content.decode())

something proves ok

but the flutter code failed

  static String webVPNUrl = "https://webvpn.jlu.edu.cn/login";
  static String webVPNUrl_login = "https://webvpn.jlu.edu.cn/do-login";

    Dio webVPN = Dio();

    var appDocDir = await getApplicationDocumentsDirectory();
    String appDocPath = appDocDir.path;

    var cj = PersistCookieJar(ignoreExpires: true, storage: FileStorage(appDocPath +"/.cookies/" ));
    webVPN.interceptors.add(CookieManager(cj));

    // var cookieJar=PersistCookieJar(storage: appDocPath+"/.cookies/");
    // webVPN.interceptors.add(CookieManager(cookieJar));

    String captcha_id = await webVPN.request(webVPNUrl).then((response) =>
        parse(response.data)
            .getElementsByClassName("captcha-div")
            .first
            .getElementsByTagName("input")
            .first
            .attributes["value"] ??
        "");
    print(captcha_id);
// captcha id seems right
    print(await cj.loadForRequest(Uri.parse("https://webvpn.jlu.edu.cn/")));
// session id seems right
    await webVPN.request(webVPNUrl_login, data: {
      "auth_type": "local",
      "username": username,
      "sms_code": "",
      "password": password,
      "captcha": "",
      "needCaptcha": "false",
      "captcha_id": captcha_id
    });
    await webVPN
        .request(
      "https://webvpn.jlu.edu.cn/,
    )
        .then((response) {
      print(response.data);
    });

the out put prove not login

276562578 avatar Aug 12 '22 08:08 276562578