diff --git a/dio/README-ZH.md b/dio/README-ZH.md index 7d86c936e..5bdc0e3e2 100644 --- a/dio/README-ZH.md +++ b/dio/README-ZH.md @@ -46,6 +46,7 @@ dio 是一个强大的 Dart HTTP 请求库,支持全局配置、Restful API、 * [HTTP/2 支持](#http2-支持) * [请求取消](#请求取消) * [继承 Dio class](#继承-dio-class) + * [Web 平台跨域资源共享 (CORS)](#web-平台跨域资源共享--cors-) @@ -853,3 +854,14 @@ class MyDio with DioMixin implements Dio { // ... } ``` + +## Web 平台跨域资源共享 (CORS) + +在 Web 平台上发送网络请求时,如果请求不是一个 [简单请求][], +浏览器会自动向服务器发送 [CORS 预检][] (Pre-flight requests), +用于检查服务器是否支持跨域资源共享。 + +你可以参考简单请求的定义修改你的请求,或者为你的服务加上 CORS 中间件进行跨域处理。 + +[简单请求]: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS#%E7%AE%80%E5%8D%95%E8%AF%B7%E6%B1%82 +[CORS 预检]: https://developer.mozilla.org/zh-CN/docs/Glossary/Preflight_request diff --git a/dio/README.md b/dio/README.md index ad02e88ba..3e0d430c5 100644 --- a/dio/README.md +++ b/dio/README.md @@ -47,6 +47,7 @@ timeout, and custom adapters etc. * [HTTP/2 support](#http2-support) * [Cancellation](#cancellation) * [Extends Dio class](#extends-dio-class) + * [Cross-Origin Resource Sharing on Web (CORS)](#cross-origin-resource-sharing-on-web--cors-) @@ -902,3 +903,16 @@ class MyDio with DioMixin implements Dio { // ... } ``` + +## Cross-Origin Resource Sharing on Web (CORS) + +If a request is not a [simple request][], +the Web browser will send a [CORS preflight request][] +that checks to see if the CORS protocol is understood +and a server is aware using specific methods and headers. + +You can modify your requests to match the definition of simple request, +or add a CORS middleware for your service to handle CORS requests. + +[simple request]: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests +[CORS preflight request]: https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request