Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass cookie in http request – Flutter

What I’m trying do is access the Instagram private api which requires user to be logged in before sending request to it, so to achieve that, I accessed the cookies or session id with the help of flutter_web_view and webview_cookie_manager (basically making the user logged in through webview and then get the cookie using cookie_manager package)

But how to pass that cookie in http request?

// accessing cookie or session id
 
  WebViewController webViewController = WebViewController()
    ..loadRequest(Uri.parse('https://www.instagram.com/'))
    ..setJavaScriptMode(JavaScriptMode.unrestricted)
    ..setNavigationDelegate(
      NavigationDelegate(
        onPageFinished: (value) async {
          final cookieManager = WebviewCookieManager();
          List<Cookie> gotCookies = await cookieManager.getCookies('https://www.instagram.com/');
          print(gotCookies); // recieved the cookies
        }
      )
    )
  ;

var response = await http.get(private_api_url}); // how to pass cookies in this request

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

var response = await http.get(private_api_url, headers: {'cookie': cookie});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading