我正在尝试为特定网站制作一个Web爬网程序API,该网站的登录名后面有一些资源,登录名在Cookies中提供了会话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());
}
POST标头:
I/flutter (11736): set-cookie: JSESSIONID=60C35F7306479DCC3A6E33C675D05995; Path=/; Secure; HttpOnly
I/flutter (11736): cache-control: no-cache
I/flutter (11736): transfer-encoding: chunked
I/flutter (11736): date: Wed, 04 Sep 2019 22:25:26 GMT
I/flutter (11736): content-type: text/html;charset=ISO-8859-1
I/flutter (11736): server: Apache-Coyote/1.1
I/flutter (11736): expires: Thu, 01 Dec 1994 16:00:00 GMT
获取标题:
I/flutter (11736): content-type: text/html;charset=ISO-8859-1
I/flutter (11736): cache-control: no-cache
I/flutter (11736): date: Wed, 04 Sep 2019 22:25:26 GMT
I/flutter (11736): transfer-encoding: chunked
I/flutter (11736): server: Apache-Coyote/1.1
I/flutter (11736): expires: Thu, 01 Dec 1994 16:00:00 GMT
由于任何原因,由于未保存cookie,因此cookie不会出现在GET标头中。我尝试从POST复制标头并在GET请求中使用它们,但仍然无法从GET访问网站上的特定资源。如何获取cookie以正确保存?