关于delete method的body

PostMan测试delete请求是正常的, 但是有个后端应用使用老版的httpClient, server端出现java.io.EOFException: Unexpected EOF read on the socket

HttpClient 3中deleteMethod是不支持body参数的 (同时造成restTemplate的exchange()执行delete请求也失败)

可以用设置代理的方式看出来, 这是个技术活, 不过验证一下过后还是移除了这段代码

private void setProxyIfNeed(CommonsClientHttpRequestFactory requestFactory) {
		if (setProxy) {
			HostConfiguration config = requestFactory.getHttpClient().getHostConfiguration();
			config.setProxy("localhost", 8866);
			Credentials credentials = new UsernamePasswordCredentials();
			AuthScope authScope = new AuthScope("localhost", 8866);
			requestFactory.getHttpClient().getState().setProxyCredentials(authScope, credentials);
		}
	}

关于delete method的body

修改HttpClient 3太麻烦, 升级spring mvc3动静又太大, 那就重写SimpleClientHttpRequestFactory

if ("PUT".equals(httpMethod) || "POST".equals(httpMethod) || "DELETE"..equals(httpMethod)) {
			connection.setDoOutput(true);
		}
上一篇:android – Eclipse中的间歇性RequestFactory错误


下一篇:@Bean使用