How can I add multiple headers in Flutter GET Api request
3,326
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.
Author by
Zain SMJ
Updated on December 09, 2022Comments
-
Zain SMJ over 1 year
how can I add set-cookie in Headers of Flutter API. I've used the following dart plugin:
I am following these links but couldn't add headers.
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; }