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.

Share:
3,326
Zain SMJ
Author by

Zain SMJ

Updated on December 09, 2022

Comments

  • Zain SMJ
    Zain SMJ over 1 year

    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;
      }