使用RestTemplate
简单实现。
String body = IOUtils.toString(request.getInputStream(), Charset.forName(request.getCharacterEncoding()));
Map<String, String[]> parameterMap = request.getParameterMap();
String method = request.getMethod();
try {
restTemplate.exchange(url,
HttpMethod.valueOf(method),
new HttpEntity<>(body),
Object.class,
parameterMap);
} catch (RuntimeException ignored) {
}
IOUtils
是commons-io
的包
url
是转发的url