-
-
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
Cannot read set-cookie from response header in Flutter Web #1027
Comments
I'm facing the same issue. |
We are seeing the same issue, using dio 3.0.10. Interestingly we have a header that the srver responds with, X-Authentication that we can see in the network tab of chrome is in the response but the header does not show up in the response headers in dio. Is there a white list of headers we need to add to to allow this header to be made available to us? I've read somewhere that chrome is consuming the set-cookie header and it is managing the cookie, which makes some sense, but does not explain why this X-Authorisation header is being consumed. Any ideas? |
我也遇到了同样的问题 |
Having the same problem any update? |
I'm facing the same issue. |
Facing the same issue, any solution? |
Just an update on this...
Running on web, hitting the same endpoint as an the android app. Both generated from the same flutter codebase generate these headers in response to the exact same RESTful call:
|
I'm facing the same issue too :( |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions. |
I just ran into the same issue with http-only cookies not beeing saved. My fix was to first configure my Flask backend to support credentials. My flutter dev instance is running in chrome on port 1234.
I then added an interceptor with
I found this solution by looking throught the dio source and found this in browser_adapter.dart:
|
I'm facing the same issue does anybody found a workaround? |
facing the same problem. |
facing the same issue. Doctor summary (to see all details, run flutter doctor -v): Desc: if set Credentials =false |
I got same problem.. |
Same here. Using Dio in Flutter Web, there seems to be no way to receive HTTP headers other than |
same issue in web . set cookie can be found in browser net response, but can't get it from code response.headers |
1 similar comment
same issue in web . set cookie can be found in browser net response, but can't get it from code response.headers |
@supermuesli @sinoory, This is more of a browser related issue. The below explanation is all what you need to know,
The header cookies from your server probably doesn't contain SameSite attribute and that's why the header cookies are not accepted by the browser. So to make it work either we have to add SameSite=None attribute in response header at server side or The web app needs to be hosted on the same domain as the server from which response is coming. |
@anikket786 seems true when run in web. But when run it on android phone , still can not find cookie from response.headers |
I'm facing the same issue. In my case I want to retrieve custom 'X-After-Cursor' header, but I can get only 2 headers: 'Content-Length' and 'Content-Type' |
same here and I also got refuse to set header "cookies" in console chrome/firefox. anyone know the solution? thanks |
I'm facing the same issue trying to retrieve a custom header from the response. Any workaround? |
Not being able to read all headers when doing a cross domain request is a browser security feature related to CORS. This is not a dio bug. If you google some articles about CORS and headers, you will find the explanation how to access the headers you're looking for. |
Hi @jgoyvaerts, really helpful mate, thanks a lot! I got this issue from ISTIO https://discuss.istio.io/t/configuring-cors/7458/6 didn't check for all the CORS headers in my response and was expecting the impossible to happen. |
for those who are not able to read custom headers, the server just sends the header "Access-Control-Allow-Headers: *" so that Dio can see all headers. https://developer.mozilla.org/pt-BR/docs/Web/HTTP/Headers/Access-Control-Allow-Headers |
I faced the same issues for flutter web! |
Any one resolved it ? Thanks! |
Hi, guys! i am facing the same problem. what should i do ? my back : django , i have set up "django-cors-headers"; |
I had the same problem that has been reported by several people here and I found a solution. First, it was necessary to add the code below, because without it the browser does not create the cookies that come in the Set-Cookie response header that comes from another domain. Read more here. Dio _dio = Dio(options);
BrowserHttpClientAdapter adapter = BrowserHttpClientAdapter();
adapter.withCredentials = true;
_dio.httpClientAdapter = adapter; The code above was taken from this comment. Check if your cookies were created at: Dev Tools > Application > Cookies. I tested many settings in the Flask-CORS library I use in my backend, but I never got a return other than As I realized that getting the import 'dart:html' as html;
var cookies = html.window.document.cookie; That way, non-HttpOnly cookies will be accessible |
@charcoast , you can still use The Instead, look at the browser settings. There I found my Also, make sure to follow this guide: https://stackoverflow.com/questions/46288437/set-cookies-for-cross-origin-requests |
Hi @makoru-hikage , I am having the same problem and can't get the cookie saved in Application tab. As you said, it's httpOnly cookies and can be seen from browser settings. But I wonder how can I have access to these cookies, for further request, because when user is authenticated, these cookies should be tagged along with other request. |
Here is an interesting article on medium: https://medium.com/swlh/flutter-web-node-js-cors-and-cookies-f5db8d6de882 |
just use flutter webview pro https://pub.dev/packages/flutter_webview_pro
and you will be fine.
…On Tue, Sep 6, 2022 at 8:10 PM NicolasLaube ***@***.***> wrote:
Here is an interesting article on medium:
https://medium.com/swlh/flutter-web-node-js-cors-and-cookies-f5db8d6de882
—
Reply to this email directly, view it on GitHub
<#1027 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGJD2U7AIARIUPKQ5OCUWFDV447DXANCNFSM4V637KPA>
.
You are receiving this because you commented.Message ID:
***@***.***>
--
Best Regards,
Sandi
|
I find the answer. BaseOptions(extra: {"withCredentials": true})); |
That is not enough for me. Access-Control-Allow-Credentials: true this works fine. |
I had the same problem with Flutter Web. Heres what I did in my Node.js backend to solve the problem. app.use(cors({
exposedHeaders: ['my-custom-header']
}));
app.options('*', cors()); Now i'm able to use the custom header in my app. |
Is there any update to this? i stille can't get the set-cookie |
I am experiencing this issue while running on localhost as well. I have tried troubleshooting it, but I haven't been able to find a solution. |
I add this to server's response headers and solved: Access-Control-Expose-Headers: xxx(the header name you want to expose). |
Require to pass above issue first. Then this is full code from my side. Step 1: Prepare 2 files. One for web and one for mobile.
file
Step 2: Create bridge file which is quite confuse with usage purpose (for
Step 3: The final file
Finally, you can use by using this (ONLY MY USE CASE):
As I said I used with my case. You can simply use by call Happy coding!!! |
There is no need to handle cookies in flutter web. Each api request from browser it will automatically added to header. If you use cross origin (app server domain and frondend domain are different), you need to configure your app server like node/express js
In flutter, use http plugin like below
BrowserClient uses XMLHttpRequest. its working fine in flutter web in production. Make sure your cookie value is below format
|
more than 3 years. |
According to #585, cookies are automatically managed by the browser, but they are not in Flutter Web. (They works well in Android/iOS). I can see a
set-cookie
value from the response header in the browser dev tap, but they are not saved in Cookies Storage and not appeared on the console when I print all the headers from the response, it only shows like the below.[Response Headers] {cache-control: no-cache, no-store, max-age=0, must-revalidate, content-type: application/json; charset=utf-8, expires: -1, pragma: no-cache}
I also tried the this code from @whimthen but it is not working for me.
There are quite many people experiencing this issue and no certain workaround. I'd appreciate there would be an exact workaround.
The text was updated successfully, but these errors were encountered: