flutterhttp-status-code-301diobad-request

Dio invalid status code of 301. Tried many things but it doesn't work


This is a reference to how the data is supposed to look:

enter image description here

This is how I did it:

Future<Response> post() async {

    try {

      //---
      final Response response = await _dio.post(
        "/api/verifyPhone",
        data: {"name": "Ali Khaled", "phone": "01111111111"},
      );
      //---

      return response;
    } catch (e) {
      rethrow;
    }
  }

Which results in DioException [bad response]: The request returned an invalid status code of 301.

I tried using jsonEncode() and headers: {"Accept":"application/json"}, but nothing seems to work.

I would really appreciate your help!

Edit

get() requests works just fine so, I think the problem is related to the data passed into the post request?

Edit 2

Deleting the data is supposed to result in "error 405, name is required", but that also didn't change the "error 301" that I get. So, the problem isn't in the data passed either?!!


Solution

  • For anyone facing the same problem

    I was able to solve it by changing URL address from http to https.

    get() requests worked, because it worked just fine with the http link, and Error 301 indicates a redirection, So the problem was definitely in the link.