在Flutter中找出Cookie

时间:2019-11-17 14:29:10

标签: authentication cookies flutter http-post httpcookie

我使用Flutter将HTTP发布到网站以进行登录。如果仅发送数据进行登录,则HTTP-Post的响应将显示我尚未登录。我试图找出网站发送的Cookie。我用软件Postman完成的。如果添加相同的cookie,我在邮递员那里,使用Flutter的HTTP-Post可以工作,并且响应显示Im已登录。过一会儿,cookie的值切换了,并且通过Flutter的HTTP-Post起作用了。

如何从网站上获取有关cookie实际价值的信息?

代码如下:

Future initiate() async {
  ByteData bytes = await rootBundle.load('assets/Certificates/test.crt');
  SecurityContext clientContext = new SecurityContext()
    ..setTrustedCertificatesBytes(bytes.buffer.asUint8List());
  var client = new HttpClient(context: clientContext);

  IOClient ioClient = new IOClient(client);
  var form = <String, String>{
    'user':'testuser',
    'pass':'testpass',
    'logintype':'login',
    'pid':'128',
    'submit':'Anmelden',
    'tx_felogin_pi1[noredirect]':'0'
  };
  print(form);

  var ris = await ioClient.get("https://www.test.de/login");
  print(ris.headers);
  http.Response res = await ioClient.post("https://www.test.de/login",body:form, headers: {
    "Accept": "application/json",
    "Content-Type": "application/x-www-form-urlencoded", "Cookie": "fe_typo_user=12345"},  encoding: Encoding.getByName("utf-8"));
  ioClient.close();
  client.close();

  print(res.body.length);
  return res.body.contains("logout");
} 

1 个答案:

答案 0 :(得分:0)

这是我获取Cookie的方法:

preact-cli