Flutter Web Dio 无法进行简单的 POST
Posted
技术标签:
【中文标题】Flutter Web Dio 无法进行简单的 POST【英文标题】:Flutter Web Dio failing to make a simple POST 【发布时间】:2021-05-26 00:10:15 【问题描述】:任何帮助将不胜感激!如果不能解决 Dio,建议 Flutter Web 使用其他哪些软件包进行 POST(我需要能够添加 followRedirect=false
,所以基本的 http
软件包已出)。谢谢!!
var resp = await Dio().post("xyz.com:1001/login", data: "user": email, "pass" : pwd)
获取
Error: Sorry, please contact support: DioError [DioErrorType.DEFAULT]: RangeError (index): Index out of range: index should be less than 1: 1
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49 throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 581:7 _get]
packages/dio/src/options.dart 301:29 get uri
packages/dio/src/adapters/browser_adapter.dart 30:37 <fn>
packages/dio/src/adapters/browser_adapter.dart 32:63 fetch
packages/dio/src/dio.dart 922:46 _dispatchRequest
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1612:54 runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 152:18 handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 704:44 handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 733:13 _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 539:5 [_completeWithValue]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 577:7 callback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15 <fn>
at Object.throw_ [as throw] (http://localhost:56880/dart_sdk.js:5331:11)
at throwError (http://localhost:56880/packages/webcargo_mobile/user/login.dart.lib.js:818:15)
at _RootZone.runUnary (http://localhost:56880/dart_sdk.js:38886:58)
at _FutureListener.catchError.handleError (http://localhost:56880/dart_sdk.js:33886:48)
at handleError (http://localhost:56880/dart_sdk.js:34448:51)
at Function._propagateToListeners (http://localhost:56880/dart_sdk.js:34474:17)
at _Future.new.[_completeError] (http://localhost:56880/dart_sdk.js:34320:23)
at _SyncCompleter.new.[_completeError] (http://localhost:56880/dart_sdk.js:33803:36)
at _SyncCompleter.new.completeError (http://localhost:56880/dart_sdk.js:33726:29)
at onError (http://localhost:56880/dart_sdk.js:33571:60)
at _RootZone.runBinary (http://localhost:56880/dart_sdk.js:38891:58)
at _FutureListener.then.handleError (http://localhost:56880/dart_sdk.js:33884:48)
at handleError (http://localhost:56880/dart_sdk.js:34448:51)
at Function._propagateToListeners (http://localhost:56880/dart_sdk.js:34474:17)
at _Future.new.[_completeWithValue] (http://localhost:56880/dart_sdk.js:34312:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:56880/dart_sdk.js:34335:35)
at Object._microtaskLoop (http://localhost:56880/dart_sdk.js:39173:13)
at _startMicrotaskLoop (http://localhost:56880/dart_sdk.js:39179:13)
at http://localhost:56880/dart_sdk.js:34686:9
【问题讨论】:
仅供参考,这也可以通过 http 包来完成。 pub.dev/documentation/http/latest/http/BaseRequest/… 感谢克里斯托弗!我将如何使用它?我可以添加到http.post(Uri.https("xyz.com:1000" , "login"), body: "user": email, "pass" : pwd)
吗?或者我是否需要使用HttpClientRequest
,如果后者我尝试过但它导致了不同的问题,请参阅***.com/questions/66339121/…
好的,参见***.com/questions/66339121/…中的代码示例
【参考方案1】:
您的网址缺少方案,例如:http://
所以尝试添加类似http://example.com/login
的方案
【讨论】:
以上是关于Flutter Web Dio 无法进行简单的 POST的主要内容,如果未能解决你的问题,请参考以下文章