I am trying to make a web-scraper API for a specific website, which has some resources locked behind a login, and the login gives a session ID in the Cookies. When I tried POSTing my login, the session ID wasn't saved to CookieJar.
Code:
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 Headers :
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
GET Headers :
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
For whatever reason, the cookies aren't present in the GET Headers as the cookies are not saved. I tried copying the headers from POST and using them in my GET request, but I still couldn't access the specific resource on the website from GET. How can I get the cookies to save properly?