Flutter - 错误:不允许 HTTP 405 方法

has*_*lah 4 api json http dart flutter

我试图通过客户端提供给我的 API 读取 json 文件,但它给出 HTTP 错误 405,表示方法不允许。谁能告诉我我做错了什么吗?

这个 api 请求片段是给我的:

curl 'http://finelistings.com/backend/apis/webbrands/' -H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary '{}' --compressed --insecure
Run Code Online (Sandbox Code Playgroud)
curl 'http://finelistings.com/backend/apis/webbrands/' -H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary '{}' --compressed --insecure
Run Code Online (Sandbox Code Playgroud)

Tor*_*ure 6

方法不允许可能是指错误的请求方法。

尝试使用 POST 而不是 GET,至少我使用上述 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);
  }
Run Code Online (Sandbox Code Playgroud)