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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM