java发送POST请求以x-www-form-urlencoded格式传参数
POST请求以x-www-form-urlencoded格式传参数MultiValueMap
设置请求头
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/x-www-form-urlencoded");
HttpEntity<MultiValueMap<String, Object>> r = new HttpEntity<>(postParameters, headers);
入参放到实体
MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
requestEntity.add("clientFlag", clientFlag);
requestEntity.add("xml", xml);
requestEntity.add("verifyData", strMd5);
HttpEntity<MultiValueMap<String, Object>> r = new HttpEntity<>(postParameters, headers);
public class HttpEntity<T> {
private final HttpHeaders headers;
private final T body;
public HttpEntity(T body, MultiValueMap<String, String> headers) {
this.body = body;
HttpHeaders tempHeaders = new HttpHeaders();
if (headers != null) {
tempHeaders.putAll(headers);
}
this.headers = HttpHeaders.readOnlyHttpHeaders(tempHeaders);
}
}
接下来就是发送POST请求 和接收参数了,用啥都行了
更多推荐
所有评论(0)