【发布时间】:2018-10-09 00:36:54
【问题描述】:
我尝试通过POST方式向SpringBoot webserver发送一个字符串,当字符串较小(200k)时,可以在控制器端接收,而当字符串较大(2M)时,控制器字段为空,没有springBoot 日志中的任何错误消息。
控制器代码sn-p为:
@PostMapping(value = "/func")
public ResponseMessage func(@RequestParam(value = "message", defaultValue = "") String message) {
if(StringUtils.isEmpty(message)) {
// alert
}
}
发件人的代码sn-p是:
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
// Create socket configuration
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true)
.setSoTimeout(180000).setSoReuseAddress(true).setTcpNoDelay(true).build();
// Configure the connection manager to use socket configuration either
// by default or for a specific host.
connManager.setDefaultSocketConfig(socketConfig);
// Validate connections after 1 minute of inactivity
connManager.setValidateAfterInactivity(180000);
connManager.setMaxTotal(100);
connManager.setDefaultMaxPerRoute(20);
// Create global request configuration
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.DEFAULT).setExpectContinueEnabled(true)
.setConnectTimeout(180000).setSocketTimeout(180000)
.setConnectionRequestTimeout(180000).build();
CloseableHttpClient hc = HttpClients.custom().setConnectionManager(connManager)
.setDefaultRequestConfig(defaultRequestConfig).setDefaultSocketConfig(socketConfig)
.build();
String encodedMsg = new String(Files.readAllBytes(Paths.get(args[0])), UTF_8);
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(Lists.newArrayList(new BasicNameValuePair("message", encodedMsg)), UTF_8);
HttpUriRequest httpPost = HttpUtils.post("http://url/func", entity);
try (CloseableHttpResponse response = hc.execute(httpPost)) {
// ...
}
我尝试在 application.properties 中添加以下 request-body-size 参数,但它似乎不起作用。有什么建议?谢谢。
multipart.maxRequestSize=30MB
multipart.maxFileSize=30MB
spring.http.multipart.maxFileSize=30Mb
spring.http.multipart.maxRequestSize=30Mb
SpringBoot:1.5.10.RELEASE
春季:4.3.14.RELEASE
【问题讨论】:
标签: spring tomcat spring-boot