使用restTemplate發送帶header的post請求

  • 邏輯
        String url = prometheusServer + api;
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        // 查詢參數
        map.add("query", sql.toString());
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/x-www-form-urlencoded");
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
        // 接受響應的類要與 接口響應一致,不然報錯
        ResponseEntity<PostResultVo> exchange = restTemplate.postForEntity(url, request, PostResultVo.class);
        if (null != exchange && null != exchange.getBody() && null != exchange.getBody().getData()) {
           
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章