我有一个在浏览器上使用Http包的应用程序。 我正在将Dart 2.4.1与angular_components一起使用。 WebStorm Ide 2019.2 我使用的方法类似于以下内容:
final String url = 'http://127.0.0.1:8080/api/check';
String postData =
'{"email":"abc@dart.com"}';
final client = BrowserClient();
Response response;
try {
response = await client.post(url,
headers: {
'Content-Type': 'application/json',
},
body: postData);
} on ClientException catch (e) {
print(e);
} catch (e) {
print(e);
} finally {
client.close();
}
但是我收到了一个带有文本“ XMLHttpRequest错误”的ClientException。 并堆叠:
Error: XMLHttpRequest error.
dart:sdk_internal 41864:30 get current
package:http/src/packages/http/src/browser_client.dart 84:22 <fn>
package:stack_trace/src/packages/stack_trace/src/stack_zone_specification.dart 129:26 <fn>
package:stack_trace/src/packages/stack_trace/src/stack_zone_specification.dart 209:15 [_run]
package:stack_trace/src/packages/stack_trace/src/stack_zone_specification.dart 129:14 <fn>
package:angular/src/core/change_detection/packages/angular/src/core/zone/ng_zone.dart 144:18 <fn>
dart:sdk_internal 28355:14 runUnary
package:angular/src/core/change_detection/packages/angular/src/core/zone/ng_zone.dart 141:18 [_runUnary]
dart:sdk_internal 99587:96 <fn>
package:stack_trace/src/packages/stack_trace/src/stack_zone_specification.dart 129:26 <fn>
package:stack_trace/src/packages/stack_trace/src/stack_zone_specification.dart 209:15 [_run]
package:stack_trace/src/packages/stack_trace/src/stack_zone_specification.dart 129:14 <fn>
package:angular/src/core/change_detection/packages/angular/src/core/zone/ng_zone.dart 144:18 <fn>
dart:sdk_internal 28355:14 runUnary
package:angular/src/core/change_detection/packages/angular/src/core/zone/ng_zone.dart 141:18 [_runUnary]
dart:sdk_internal 28515:34 <fn>
at Object.dart.createErrorWithStack (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:4617:12)
at onError (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:22719:44)
at Object.dart._checkAndCall (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:4787:16)
at Object.dart.dcall (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:4812:17)
at http://localhost:53322/packages/stack_trace/src/chain.ddc.js:850:127
at src__stack_zone_specification.StackZoneSpecification.new.[_run] (http://localhost:53322/packages/stack_trace/src/chain.ddc.js:893:16)
at http://localhost:53322/packages/stack_trace/src/chain.ddc.js:850:95
at http://localhost:53322/packages/angular/src/core/change_detection/change_detection.ddc.js:2435:18
at async._rootRunBinary (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:28744:56)
at async._ZoneDelegate.new.runBinary (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:28361:14)
at src__core__zone__ng_zone.NgZone.new.[_runBinary] (http://localhost:53322/packages/angular/src/core/change_detection/change_detection.ddc.js:2432:21)
at async._CustomZone.new.runBinary (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:28569:14)
at _FutureListener.then.handleError (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:24650:52)
at handleError (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:25118:51)
at Function._propagateToListeners (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:25141:17)
at _Future.new.[_completeError] (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:25004:23)
at http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:25037:31
at http://localhost:53322/packages/angular/src/core/change_detection/change_detection.ddc.js:2401:11
at src__stack_zone_specification.StackZoneSpecification.new.[_run] (http://localhost:53322/packages/stack_trace/src/chain.ddc.js:893:16)
at http://localhost:53322/packages/stack_trace/src/chain.ddc.js:840:71
at http://localhost:53322/packages/angular/src/core/change_detection/change_detection.ddc.js:2415:18
at async._rootRun (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:28729:14)
at async._ZoneDelegate.new.run (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:28349:14)
at src__core__zone__ng_zone.NgZone.new.[_run] (http://localhost:53322/packages/angular/src/core/change_detection/change_detection.ddc.js:2412:21)
at async._CustomZone.new.run (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:28555:14)
at async._CustomZone.new.runGuarded (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:28472:14)
at async._AsyncCallbackEntry.new.callback (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:28511:33)
at Object.async._microtaskLoop (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:25352:13)
at async._startMicrotaskLoop (http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:25358:13)
at http://localhost:53322/packages/build_web_compilers/src/dev_compiler/dart_sdk.js:25433:9
奇怪的是,我已经工作了两个小时,突然停了下来。
在控制台中,我得到:
Access to XMLHttpRequest at 'http://127.0.0.1:8080/api/check' from origin 'http://localhost:53322' has been blocked by CORS policy: Request header field x-ijt is not allowed by Access-Control-Allow-Headers in preflight response.
我尝试在命令行程序(使用IOClient)中使用相同的方法,并且一切正常。 我试图回滚到webdev 2.3.0(当我检查我使用的是2.4.0时),但没有任何变化。
更多,在控制台中,我还收到一条错误信息,该错误与类似我的错误之一的消息中检索roboto字体一样。
Access to font at 'https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Mu4mxK.woff2' from origin 'http://localhost:53322' has been blocked by CORS policy: Request header field x-ijt is not allowed by Access-Control-Allow-Headers in preflight response.
index.html:1GET https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Mu4mxK.woff2 net::ERR_FAILED
请注意,一切正常,我今天没有更改应用程序的配置。
有没有提示?
更新1: 仔细搜索一下,我发现此页面: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000715304-Problem-with-Chrome-plugin-and-CORS
除非您在“设置” |“设置”中设置“允许未签名的请求”,否则他的IDE似乎添加了“ x-ijt
”标头。构建,执行,部署|调试器。
我尝试过了,这样就可以了。 现在,我想了解为什么在我的工作会议期间发生这种情况,而无需更改配置。 有人可以帮忙吗?