黑豹程序员-使用RestTemplate模板对象进行访问

需求

如何直接java程序直接请求另外一个web网址

使用RestTemplate模板对象进行访问

    public static void main(String[] args) {
        RestTemplate restTemplate = new RestTemplate();

        String url = "http://localhost:6080/risk/center/find?pageNum=1&pageSize=50";

        // 发送GET请求
        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);

        // 获取响应数据
        String responseBody = response.getBody();

        // 打印响应结果
        System.out.println("Response body: " + responseBody);
    }

日志

11:55:44.298 [main] DEBUG org.springframework.web.client.RestTemplate - HTTP GET http://localhost:6080/risk/center/find?pageNum=1&pageSize=50
11:55:44.322 [main] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/x-jackson-smile, application/cbor, application/*+json, */*]
11:55:44.466 [main] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK
11:55:44.468 [main] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json"
Response body: {"code":200,"msg":"接口调用成功","data":{"records":[...] } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值