Flutter - ERROR : HTTP 405 Method not allowed

Viewed 3967

I'm trying to read json file through an API that was given to me by a client, but It's giving HTTP error 405 saying method not allowed. Can anyone please tell what I'm doing wrong?

This api request snippet was given to me :

curl 'http://finelistings.com/backend/apis/webbrands/' -H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary '{}' --compressed --insecure
Future<String> getData() async {
    var response = await http.get(
      Uri.encodeFull("http://finelistings.com/backend/apis/webbrands/"),
      headers: {
        "Accept": "application/json",
      }
    );

    Map<String, String> data = jsonDecode(response.body);

    print(data);
  }

1 Answers

Method not allowed might refer to wrong request method.

Try using POST instead of GET, at least I got a response from that using the mentioned URL.

Future<String> getData() async {
    var response = await http.post(
      Uri.encodeFull("http://finelistings.com/backend/apis/webbrands/"),
      headers: {
        "Accept": "application/json",
      }
    );

    Map<String, dynamic> data = jsonDecode(response.body);

    print(data);
  }
Related