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

问题描述 投票:2回答:1

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

我的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(),
            ),
          ),
    );
  }
json flutter http-delete
1个回答
0
投票

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

String url = "http://35.186.145.243";

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

© www.soinside.com 2019 - 2024. All rights reserved.