java 简单的 request 转发

Drinker 后端 2021-03-11

使用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

中文版Postman,rap文档管理

评论