首页 > 解决方案 > 如何解决flutter中的http请求错误

问题描述

我想从我自己的 PHP 文件中获取我的颤振应用程序中的数据,我在其中 echo jsonEncode(object);

但它给出以下错误:

Error: XMLHttpRequest error.
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28                get current
packages/http/src/browser_client.dart 71:22                                       <fn>
dart-sdk/lib/async/zone.dart 1612:54                                              runUnary
dart-sdk/lib/async/future_impl.dart 152:18                                        handleValue
dart-sdk/lib/async/future_impl.dart 704:44                                        handleValueCallback
dart-sdk/lib/async/future_impl.dart 733:13                                        _propagateToListeners
dart-sdk/lib/async/future_impl.dart 530:7                                         [_complete]
dart-sdk/lib/async/stream_pipe.dart 61:11                                         _cancelAndValue
dart-sdk/lib/async/stream.dart 1219:7                                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39  dcall
dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58                              <fn>
    at Object.createErrorWithStack (http://localhost:42101/dart_sdk.js:5347:12)
    at Object._rethrow (http://localhost:42101/dart_sdk.js:39349:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:42101/dart_sdk.js:39343:13)

我的颤动代码在哪里给出错误..

  getdata() async {
    typesOfc = await http.get(Uri.parse("http://localhost:4545/"));
    print(jsonDecode(typesOfc));
  }

我正在使用 http 插件

我的PHP代码..


if($action == 'fetchData'){
   $fetchQuery = "SELECT `NAME` , `PASSWORD` FROM `REGISTER`";
   $FetchResult = mysqli_query($connectLhost , $fetchQuery);
   $data = array();
   if($FetchResult->num_rows > 0){
    while($row = $FetchResult->fetch_assoc()){
        $data[]  = $row;  
    } 
   echo json_encode($data);
   }else{
    echo "Cant FetchData";
   }
}                

标签: phpandroidflutterhttpcross-platform

解决方案


推荐阅读