• restTemplate.getForEntity restTemplate.getForObject GET请求


    //带参数
    @Test
        public void testGet1(){
            
            String url = "http://IP:PORT/query?token={token}&memNo={memNo}";
            RestTemplate restTemplate = new RestTemplate();
    
            Map<String,Object> paramMap=new HashMap<>();
            paramMap.put("token","111");
            paramMap.put("memNo", "222");
            
        
            ResponseEntity<String> zhimaAuthResponse = restTemplate.getForEntity(url, String.class, paramMap);
    //        String zhimaAuthResponse = restTemplate.getForObject(url, String.class, paramMap);
            System.out.println(zhimaAuthResponse.getStatusCode());
            if (HttpStatus.OK == zhimaAuthResponse.getStatusCode()) {
                System.out.println(zhimaAuthResponse.getBody());
                System.out.println(zhimaAuthResponse.getHeaders());
            }
            
        }
        
        
        //不带参数
        @Test
        public void testGet2(){
            String url = "http://IP:PORT/refreshcache";
            
            RestTemplate restTemplate = new RestTemplate();
            
            ResponseEntity<String> zhimaAuthResponse = restTemplate.getForEntity(url, String.class);
            System.out.println(zhimaAuthResponse.getStatusCode());
            if (HttpStatus.OK == zhimaAuthResponse.getStatusCode()) {
                System.out.println(zhimaAuthResponse.getBody());
                System.out.println(zhimaAuthResponse.getHeaders());
            }
            
        }
        
        
  • 相关阅读:
    pom.xml基础配置
    Maven零散笔记——配置Nexus
    搭建局域网maven仓库
    java 加密解密
    菠萝大象--sping
    (转)Spring对注解(Annotation)处理源码分析1——扫描和读取Bean定义
    eclipse 如何把java项目转成web项目
    Effective Java
    More Effective C++
    Effective C++
  • 原文地址:https://www.cnblogs.com/oktokeep/p/13326987.html
Copyright © 2020-2023  润新知