When using Dio in a web environment, is there a way to disable Dio’s automatic cookie setting? #2198
Closed
momadvisor
started this conversation in
General
Replies: 1 comment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I encountered the following error:
DioException [connection error]: The connection errored: The XMLHttpRequest onError callback was called. This typically indicates an error on the network layer. This indicates an error which most likely cannot be solved by the library.
This occurs only in web environment. After researching and analyzing, I realized that it was a CORS issue. The URL I’m requesting is api.xxx.com (with the subdomain api.). This URL doesn’t require any cookies and also doesn’t set any set-cookie headers. However, If Chrome has cookies for xxx.com (the root domain) stored locally, It seems that Dio client sets cookies even for requests to api.xxx.com, which results to CORS errors.
Solution Attempt 1 (Success): I resolved the issue by using the package:http/http.dart library instead of Dio library.
Limitation of Attempt 1: The challenge remains in unifying the HTTP client across different environments (http library for web and dio library for non-web).
Attempt 2 (Failure): I tried using a Dio interceptor to set cookies to an empty string:
));
but it failed with same debug messages.
How to handle this situation?
Beta Was this translation helpful? Give feedback.
All reactions