Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request error with path #6

Closed
CaiJingLong opened this issue May 15, 2018 · 5 comments
Closed

request error with path #6

CaiJingLong opened this issue May 15, 2018 · 5 comments

Comments

@CaiJingLong
Copy link
Contributor

StackTrace


[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
DioError [DioErrorType.DEFAULT]: RangeError (index): Invalid value: Only valid value is 0: 1#0      List.[] (dart:core/runtime/libgrowable_array.dart:141:60)
#1      Dio._makeRequest (package:dio/src/Dio.dart:341:30)
<asynchronous suspension>
#2      Dio._request.<anonymous closure> (package:dio/src/Dio.dart:320:16)
#3      Dio._checkIfNeedEnqueue (package:dio/src/Dio.dart:556:22)
#4      Dio._request (package:dio/src/Dio.dart:291:21)
<asynchronous suspension>
#5      Dio.request (package:dio/src/Dio.dart:274:12)
<asynchronous suspension>
#6      Dio.post (package:dio/src/Dio.dart:75:12)
#7      __LoginPageState&State&SizeUtils&HttpHelper.fetchWithDio (package:my_app/util/utils.dart:98:30)
<asynchronous suspension>
#8      _LoginPageState._login (package:my_app/pages/LoginPage.dart:366:32)
<asynchronous suspension>
#9      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:494:14)
#10     _InkResponseState.build.<anonymous <…>

my code

Dio dio = new Dio()
  ..options.baseUrl = new HttpUrl.get().host + "/"
  ..options.connectTimeout = 5000
  ..options.receiveTimeout = 5000;
var data = new FormData.from(params);
    data.add("a", httpUrl);
    data.add("m", url.m);
    var response = await dio.post("rest.php", data: data);
    return response.data;

describe

My base url is http://www.xxx.com/rest.php.

Using the parameters of the form to distinguish the business logic.

If URL does not apply to restful, can you not use your plugin?

@wendux
Copy link
Contributor

wendux commented May 15, 2018

What's the result of new HttpUrl.get().host + "/" ? It seems to not start with "http(s)". The base url must start with "http(s)", you can try again as follows:

Dio dio = new Dio()
  ..options.baseUrl = "http://www.xxx.com/";
...
var response = await dio.post("rest.php", data: data);

@CaiJingLong
Copy link
Contributor Author

Thx, dart:io's HTTP does not need to start with http/https, I did not modify this part of the code in my code.

@wendux wendux closed this as completed Jul 14, 2018
@TensaiZero
Copy link

I am having this issue as well.. Only occurs on dio.post... if I do a hot reload, without changing anything on the code the dio.post works. But if I restart the app using flutter run, the error occurs again.

@wendux
Copy link
Contributor

wendux commented Sep 5, 2018

@TensaiZero Could you provide some debug info? if the baseurl is right when you restart? May you need to add some "print" logs or breakpoints .

:octocat: From gitme Android

@TensaiZero
Copy link

@wendux Got it , just the base url. Thank you very much. Haven't initialized it on start.

@fly512 fly512 mentioned this issue Jan 7, 2019
AlexV525 added a commit that referenced this issue Feb 13, 2023
…was set (#6)

Co-authored-by: ipcjs.mac <gipcjs@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants