我正在尝试为特定网站制作一个网页抓取API,该网站在登录后锁定了一些资源,并且登录在 Cookie 中提供了一个会话 ID。当我尝试发布登录信息时,会话 ID 未保存到 CookieJar。
代码:
var dio = new Dio()
..interceptors.add(CookieManager(CookieJar()));
login(String username, String password) async{
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) { client.badCertificateCallback = (X509Certificate cert, String host, int port) => true; return client; };
var response1 =await dio.post("https://www.codestepbystep.com/login", data:{"usernameoremail": username, "password":password, "login":"Login", "userkeepmeloggedin":"on", "after" : "after", "timezone" : "America/Chicago", "timezoneoffset" : "-360"});
debugPrint(response1.headers.toString());
var response = await dio.get("https://www.codestepbystep.com/problem/view/c/basics/hello_world");
debugPrint(response.headers.toString());
}
Run Code Online (Sandbox Code Playgroud)
POST 标题:
I/flutter (11736): set-cookie: JSESSIONID=60C35F7306479DCC3A6E33C675D05995; Path=/; Secure; HttpOnly
I/flutter (11736): cache-control: no-cache
I/flutter …Run Code Online (Sandbox Code Playgroud)