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;
// 封装请求头
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<>(
headers);
ResponseEntity<Map> exchange = restTemplate
.exchange(
"http://127.0.0.1:8090/user",
HttpMethod.GET, formEntity, Map.class);
String loginName = "";
if (exchange.getStatusCode().toString().trim().equals("200")) {
JSONObject body = new JSONObject(exchange.getBody());
if (new Integer(200).equals(body.get("code"))) {
JSONObject data = body.getJSONObject("data");
String loginName = data.getString("loginName");
}
}