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

标签 json flutter http-delete

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

我的 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/

相关文章:

json - 如何在 Haskell 中解析 exiftool JSON 输出的示例

java - GWT JSON 解析正在删除\字符

java - JSON JAX-RS channel : Failed to find resource/HtmlDefaultRepresentation/defaultHtmlEntry. jsp

android - JSONObject.toString() 将内部 JSONArray 转换为 Android 中的字符串

dart - 在 dart 的依赖版本控制中加一 (+1) 是什么意思

Flutter Web 平台检查

java - 如何在 java 中使用 HTTPDELETE 作为 RequestBody 发送列表参数

dart - 如何使用 android_intent 通过 flutter 打开位置设置

java - HttpDelete 参数与 setEntity 在 android 上?

spring-boot - aws elasticsearch 签名删除请求返回 403 forbidden(使用 apache httpclient)