我如何从api删除请求? -扑

时间:2019-03-05 09:11:36

标签: json flutter http-delete

我知道如何获取和发布请求,但是不确定如何删除请求?

我的json网址及其要求:

String url = "http://35.186.145.243:8080/users";

{
"userId":"user1",
"price":"$1.300"
}

所以我需要传递userId和price作为参数,以便从api中删除信息

  main() async {
    String url = "http://35.186.145.243:8080";

    Map map = {
      'user_id': "user1",
      'price': "$1.300",
    };

    print(await apiRequest(url, map));
  }

  Future<String> apiRequest(String url, Map jsonMap) async {
    HttpClient httpClient = new HttpClient();
    httpClient.open('delete', url, 0, '/users');
    httpClient.close();
    return 'Success';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("API DELETE"),
      ),
      body:
          Center(
            child: RaisedButton(
              color: Colors.lightBlueAccent,
              child: Text("DELETE!"),
              onPressed: () => main(),
            ),
          ),
    );
  }

1 个答案:

答案 0 :(得分:0)

尝试从URL中删除端口号,并将其添加到http open方法中的port参数中。

String url = "http://35.186.145.243";

httpClient.open('delete', url, 8080, '/users');