0
点赞
收藏
分享

微信扫一扫

SpringCloud: RestTemplate 带header发送get请求


package cn.edu.tju;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class TestRequest2 {
public static void main(String[] args) {
RestTemplate restTemplate = new RestTemplate();
String url="http://localhost:8097/hiHeader2";

HttpHeaders headers = new HttpHeaders();
headers.add("token", "abcdefghijklmnopqrstuvwxyz1234567890");
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(headers);

ResponseEntity<String> resultEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
System.out.println(resultEntity.getBody());



}
}


举报

相关推荐

0 条评论