-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
When using Dio in a web environment, there needs to be a way to disable Dio’s automatic cookie setting #2199
Comments
Thanks. But Its default value is false. And even when I set it false, It occurs an same error. I think the 'Origin' header should not exist.
This is an error message on the chrome console. |
Then it should not related to Cookies. The request itself might considered CORS. |
I wonder why It can be resolved just by replacing dio client with http library? Maybe, doesn't http library set the Origin header?(Maybe, in contrast, dio client sets the Origin header) |
Yea. you're right. After more debugging, I found the problem was not related to cookies, but to header fields. But until now, I couldn't find exactly and specifically which is a problem and how to solve it |
Maybe #2125 (comment) |
After removing 'contentType' property, It is solved. dio: 5.4.2+1 BEFORE
AFTER
I wish it can help someone who are under same issues and I also wish this can help you, author, to develop this lovable library. (deeply appreciate your efforts) |
See https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests which defines the list of content-type which could be treated as simple requests. |
Request Statement
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?
Solution Brainstorm
No response
The text was updated successfully, but these errors were encountered: