metadata_fetch
metadata_fetch copied to clipboard
Doesn't work for Flutter Web, fails with XMLHttpRequest error
Stack Trace
` Error: XMLHttpRequest error.
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current
packages/http/src/browser_client.dart 71:22
at Object.createErrorWithStack (http://localhost:53250/dart_sdk.js:5348:12)
at Object._rethrow (http://localhost:53250/dart_sdk.js:39350:16)
at async._AsyncCallbackEntry.new.callback (http://localhost:53250/dart_sdk.js:39344:13)
at Object._microtaskLoop (http://localhost:53250/dart_sdk.js:39176:13)
at _startMicrotaskLoop (http://localhost:53250/dart_sdk.js:39182:13)
at http://localhost:53250/dart_sdk.js:34689:9`
I tried to run the sample code and it fails, Is this a known bug ?
Same issue happened to me, is there any workaround or solution?
Your backend must have an endpoint that accepts OPTIONS request (it's called a Preflight request) and send response with status code 204 to it. Literally if you request GET https://example.com/users/profile a browser will first try to do it with OPTIONS https://example.com/users/profile and when it gets 204 then it will try GET. Make sure your backend can process it
Then why does it work with flutter mobile ?
On Tue, May 25, 2021, 9:23 PM Konstantin Serov @.***> wrote:
Your backend must have an endpoint that accepts OPTIONS request (it's called a Preflight request) and send response with status code 204 to it. Literally if you request GET https://example.com/users/profile a browser will first try to do it with OPTIONS https://example.com/users/profile and when it gets 204 then it will try GET. Make sure your backend can process it
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jg-l/metadata_fetch/issues/26#issuecomment-847989550, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBQRDMAR47RLP6CSYJG6ILTPPBWTANCNFSM4ZDQQR4A .
Because Flutter mobile is not a browser. Only web browsers send Preflight requests. Google "preflight request" if you want to know more
this solves the issue for testing locally
https://stackoverflow.com/questions/65630743/how-to-solve-flutter-web-api-cors-error-only-with-dart-code
I have the same issue, and we are going across sites to fetch meta data. For example, if someone posts a YouTube link. How can we get around this?