Dart - Request GET with cookie

前端 未结 3 1482
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 21:32

I\'m trying to make a get request but I need to put the cookie.

Using the curl works:

curl -v --cookie \"sessionid=asdasdasqqwd\"

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-05 21:53

    I used the following method, in addition to rafaelcb21's answer above:

    String stringifyCookies(Map cookies) =>
          cookies.entries.map((e) => '${e.key}=${e.value}').join('; ');
    
    // Used like so..
    http.response response = await http.get(
          'https://google.com', 
          headers: { 'Cookie': stringifyCookies(cookies) });
    

提交回复
热议问题