gpt4 book ai didi

json - 我如何从 api 发出删除请求? - flutter

转载 作者:IT王子 更新时间:2023-10-29 06:45:28 29 4
gpt4 key购买 nike

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

我的 json url 及其要求:

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(),
),
),
);
}

最佳答案

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

String url = "http://35.186.145.243";

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

关于json - 我如何从 api 发出删除请求? - flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54999145/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com