Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot retrieve multiple 'set-cookies' #64

Closed
rizkyputrapb opened this issue Apr 26, 2022 · 2 comments
Closed

cannot retrieve multiple 'set-cookies' #64

rizkyputrapb opened this issue Apr 26, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@rizkyputrapb
Copy link

hey, im having a hard time to retrieve multiple 'set-cookies' from my API. as illustrated below, the Postman is receiving 2 'set-cookies' but the Requests can only retrieve 1. is there any workaround on this? thank you!

Future<LoginModel> login(String email, String password) async {
  final uri = _baseUrl + "/login";
  Map<String, String?> body = {
    'email': email,
    'password': password,
  };
  final response = await Requests.post(uri, body: body, persistCookies: true);
  if (response.success) {
    print("success");
  
    //check for cookies
    var cookie = await Requests.getStoredCookies(Requests.getHostname(uri));
    print("cookie length: $cookie");
    print("cookie user: ${cookie["user"]}");
    print("cookie token_id: ${cookie["token_id"]}");
  
    return LoginModel.fromJson(json.decode(response.content()));
  } else {
    print(response.statusCode);
    response.throwForStatus();
    throw Exception('Failed to login');
  }
}
Future<UserModel> getUserDetail() async {
    final uri = _baseUrl + "/user";
    final response = await Requests.get(uri);
    print(response);
    if (response.success) {
      print("success");
      return UserModel.fromJson(json.decode(response.content()));
    } else {
      print(response.statusCode);
      response.throwForStatus();
      throw Exception('Failed to retrieve user info');
    }
  }

image
image

@sehnryr
Copy link
Collaborator

sehnryr commented Apr 26, 2022

I think I know why. The current parsing algorithm of the releases is broken as it does not fully extract the cookies. The issue was that http would concatenate all the SET-COOKIES headers with ,. #47 fixed that but I want to wait for #63 to create a new release.

Alternatively you can install the package via git like so:

dependencies:
  requests:
    git:
      url: https://github.com/jossef/requests
      ref: master

@sehnryr sehnryr added the bug Something isn't working label May 6, 2022
@sehnryr
Copy link
Collaborator

sehnryr commented May 6, 2022

Normally this issue has be fixed with the new 4.2.0 update.

@sehnryr sehnryr closed this as completed May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants