Java request 请求转发,可用于公共微信号推送

Posted by 浮生 on 03-31,2020

使用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) {
}

IOUtilscommons-io的包
url是转发的url