how can I add set-cookie in Headers of Flutter API. I've used the following dart plugin:
Dart Plugin
I am following these links but couldn't add headers.
Flutter Cookbook
Stackoverflow Question
Below is my Code:
Future<Map> getApi() async {
Map<String, String> headers = {};
// HEADERS TO BE ADDED
headers['Set-Cookie'] = "user_image=; Path=/";
headers['Set-Cookie'] = "user_id=Administrator; Path=/";
headers['Set-Cookie'] = "system_user=yes; Path=/";
headers['Set-Cookie'] = "full_name=Administrator; Path=/";
headers['Set-Cookie'] = "sid=123456789; Expires=Mon, 25-Feb-2019 11:01:39 GMT; Path=/";
// API RESPONSE
http.Response response = await http.get(
apiUrl,
headers: headers,
);
// CONVERT TO JSON AND MAP
Map responseBody = convert.jsonDecode(response.body);
return responseBody;
}
With the help of the solution given on this link I was able to solve my issue. Below is the HTTP request to add headers:
http.Response response = await http.get(
apiUrl,
headers: {'Cookie': 'sid=123456789'},
);
Thanks for the help guys.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With