http icon indicating copy to clipboard operation
http copied to clipboard

Cookie inside Request Header

Open Ankit0080 opened this issue 4 years ago • 1 comments

I need to get data from one of my backend services and this request uses session cookie in header. I have the session cookie but when i am sending it to server it is not working the code is throwing exception. I might be wrong passing the cookie to request header Any help would be appreciated . Thanks in advance. I am sharing my code below

/////////**This is my url//////////

Url --->> http://95.217.5.45:8081/api/home

setState(() { _isLoading = true; });

String apiUrl = ApiService.HOMEPAGE;
var response =
    await http.get(Uri.parse(apiUrl), headers: {"cookie": token});

//////////////**************This is the error i am getting below *****************/////////////////

image

//////////////**************This is the Postman Screenshot *****************/////////////////

It is working fine with postman

image

Ankit0080 avatar Sep 27 '21 05:09 Ankit0080

I have the same problem. Can't make request with cookie.

This is how it's done in curl:

curl -sS -I "url" -H "Cookie: sjv=123"

This is how it's done in python

import requests

response = requests.head('url', cookies={'sjv': '123'})

Dart http not working:

import 'package:http/http.dart' as http;

void main() async {
  var res = await http.head('url', headers: {'Cookie': 'sjv=123'});
  
  print(res.body);
}

lavara123 avatar Jan 06 '22 19:01 lavara123