如何从 Flutter Web 中的 google url 获取数据
Posted
技术标签:
【中文标题】如何从 Flutter Web 中的 google url 获取数据【英文标题】:How can I get data from google url in flutter web 【发布时间】:2021-04-11 04:17:10 【问题描述】:我使用包 [http]https://pub.dev/packages/http 从这个 url https://trends.google.com.vn/trends/api/stories/VN_lnk_GMomYwEwAAA_GM_vi?hl=en-US&tz=-420 获取数据
import 'package:http/http.dart' as http;
String url = "https://trends.google.com.vn/trends/api/stories/VN_lnk_GMomYwEwAAA_GM_vi?hl=en-US&tz=-420";
http.Response response = await http.get(url);
然后它抛出错误:
Running with unsound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Debug service listening on ws://127.0.0.1:54796/m1rEikri7V4=/ws
/
/home
Error: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current
packages/dio/src/adapters/browser_adapter.dart 79:20 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1446:54 runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 150:18 handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 703:44 handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 732:32 _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 526:7 [_complete]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_pipe.dart 61:11 _cancelAndValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream.dart 1302:7 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14 _checkAndCall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39 dcall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/html/dart2js/html_dart2js.dart 37312:58 <fn>
at Object.createErrorWithStack (http://localhost:54668/dart_sdk.js:4368:12)
at Object._rethrow (http://localhost:54668/dart_sdk.js:38289:16)
at async._AsyncCallbackEntry.new.callback (http://localhost:54668/dart_sdk.js:38283:13)
at Object._microtaskLoop (http://localhost:54668/dart_sdk.js:38115:13)
at _startMicrotaskLoop (http://localhost:54668/dart_sdk.js:38121:13)
at http://localhost:54668/dart_sdk.js:33618:9
我测试了其他工作很好。如何从这个 url 获取数据?
【问题讨论】:
能否粘贴您收到的确切错误消息。 我已经更新了错误信息。 当您说您使用的是 http 包时,您从 dio 包中得到一个错误? 都是一样的,dio包是包裹http 【参考方案1】:XMLHttpRequest 错误通常意味着您的 Cors 策略配置不正确。
See here
【讨论】:
你尝试用我的网址请求吗?以上是关于如何从 Flutter Web 中的 google url 获取数据的主要内容,如果未能解决你的问题,请参考以下文章
Flutter for Web 中的 WebView 未加载 Google 地图或其他
如何让 Google reCaptcha 为 Flutter web 工作?
Flutter web google_sign_in:如何检索refreshToken
如何在flutter中将标记从firebase(真实数据库)检索到新的google maps api
在 Flutter 中 - 从 Web 浏览器中的 PayPal 完成交易页面返回后,如何将用户推送到应用程序中的“谢谢”页面