Comments (8)
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) Still wonder why and how but anyway It is solved...
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.
from dio.
https://pub.dev/documentation/dio/latest/browser/BrowserHttpClientAdapter/withCredentials.html
from dio.
https://pub.dev/documentation/dio/latest/browser/BrowserHttpClientAdapter/withCredentials.html
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.
dioClient.options.extra['withCredentials'] = false;
This is an error message on the chrome console.
Access to XMLHttpRequest at 'https://api.xxx.com/' from origin 'http://localhost:10545' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
from dio.
Then it should not related to Cookies. The request itself might considered CORS.
from dio.
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)
from dio.
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
from dio.
Maybe #2125 (comment)
from dio.
After removing 'contentType' property, It is solved.
dio: 5.4.2+1
flutter: 3.19.2
chrome: 124.0.6367.61 (windows 10)
BEFORE
final client = Dio(
BaseOptions(
baseUrl: 'https://api.xxx.com/',
connectTimeout: const Duration(seconds: 5),
receiveTimeout: const Duration(seconds: 10),
headers: {
HttpHeaders.userAgentHeader: ua,
},
contentType: Headers.jsonContentType,
responseType: ResponseType.json,
),
);
AFTER
final client = Dio(
BaseOptions(
baseUrl: 'https://api.xxx.com/',
connectTimeout: const Duration(seconds: 5),
receiveTimeout: const Duration(seconds: 10),
headers: {
HttpHeaders.userAgentHeader: ua,
},
// remove this property
//contentType: Headers.jsonContentType,
responseType: ResponseType.json,
),
);
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)
Still wonder why and how but anyway It is solved...
from dio.
Related Issues (20)
- 503 Status Code With the Https base URL HOT 1
- DIo not working while adding extras in requestOptions with path in Dio singleton HOT 3
- Type Casting Error: '_Map<String, dynamic>' is not a Subtype of 'T?' HOT 1
- Issue with API call when android device is connected via wifi. HOT 1
- Uploading with FormData throws a TypeError: type 'List<int>' is not a subtype of type 'Uint8List' of 'value' HOT 6
- Opportunity to improve the json decoding performance HOT 3
- FormData and List of Int not working as expected. HOT 2
- flutter dynamic coockies management HOT 1
- post请求超时无反应 HOT 1
- Error Dio flutter web HOT 1
- upload file send timeout
- Header is out of order HOT 3
- `ResponseType.stream` is not working on web. HOT 1
- [🔔 Dio] sendTimeout cannot be used without a request body to send HOT 2
- `Transformer.isJsonMimeType` throws format exceptions without caught
- onError is not returning any error HOT 3
- Error when uploading image using MultipartFile.fromBytes in version 5.4.3+1 HOT 1
- 为什么dio的fromMap会将MultipartFile自动放入files字段中 HOT 1
- Error: The method 'debugLog' isn't defined for the class 'BrowserHttpClientAdapter'. HOT 1
- Version 5.5.0 brakes the web build HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dio.