【JAVA使用Hutool工具类实现DELETE请求的调用】

JAVA使用Hutool工具类实现DELETE请求的调用

1、Postman请求示例

  • Params:包含nonce、timestamp参数
    在这里插入图片描述
  • Header:包含鉴权签名,此处省略系统内部签名获取方式
    在这里插入图片描述
  • Body:包含node_id、user_id
    在这里插入图片描述
  • Postman返回结果
    在这里插入图片描述

2、maven依赖

  • hutool依赖
<dependency>
   <groupId>cn.hutool</groupId>
   <artifactId>hutool-all</artifactId>
   <version>5.0.6</version>
</dependency>
  • JSONObject依赖
<dependency>
    <groupId>net.sf.json-lib</groupId>
    <artifactId>json-lib</artifactId>
    <version>2.2.2</version>
    <classifier>jdk15</classifier>
</dependency>

3、代码实现

  使用hutool工具类,来实现DELETE请求的接口调用,以下是代码实现,部分接口地址及参数因涉及隐私问题,已做处理。


import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import net.sf.json.JSONObject;

/**
 * @author zyq
 * @description DELETE调用请求
 * @create 2024-03-26 10:52
 */
public class IdmeshRequest {
    public static void main(String[] args) {
        //从节点移除用户接口-测试
        String url = "https://console.xxx.xxx/api/v1/tree-users?nonce=a1i80lj8uv1aarkj8g7o&timestamp=1711420695172";
        //封装json请求body
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("node_id", "1742xxxxxxxxxxxxxxx936");
        jsonObject.put("user_id", "174xxxxxxxxxxxxxx12480");
        System.out.println(jsonObject);
        // 创建 DELETE 请求
        HttpRequest request = HttpUtil.createRequest(Method.DELETE, url)
                .header("X-Idmesh-Signature","XdCxxxxxxxxxx4Ysp7jG$sm3$a84839c7a71xxxxxxxxxxxxd8b4e7b0da2a1axxxxxxxxxxxx0706a6f")
                .body(jsonObject.toString());
        // 执行请求并获取响应
        HttpResponse response = request.execute();
        // 输出响应内容
        System.out.println(response.body());
    }
}

4、代码执行返回结果

在这里插入图片描述

  • 9
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值