下面列出了org.springframework.http.HttpMethod#POST 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private ServerWebExchange exchange(MultiValueMap<String, String> formData) {
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.POST, "/");
new FormHttpMessageWriter().write(Mono.just(formData),
forClassWithGenerics(MultiValueMap.class, String.class, String.class),
MediaType.APPLICATION_FORM_URLENCODED, request, Collections.emptyMap()).block();
return MockServerWebExchange.from(
MockServerHttpRequest
.post("/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.body(request.getBody()));
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
private OperationRequest requestPostWithXmlContentType() {
return new OperationRequest() {
@Override
public byte[] getContent() {
String content = "<name>foo</name>";
return content.getBytes(Charset.forName("UTF-8"));
}
@Override
public String getContentAsString() {
return "<name>foo</name>";
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Content-Type", MediaType.APPLICATION_XML_VALUE);
return httpHeaders;
}
@Override
public HttpMethod getMethod() {
return HttpMethod.POST;
}
@Override
public Parameters getParameters() {
return null;
}
@Override
public Collection<OperationRequestPart> getParts() {
return null;
}
@Override
public URI getUri() {
return URI.create("https://foo/bar");
}
@Override
public Collection<RequestCookie> getCookies() {
return Collections.emptySet();
}
};
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
/**
* Create a {@link MockHttpServletRequestBuilder} for a POST request.
* @param uri the URL
* @since 4.0.3
*/
public static MockHttpServletRequestBuilder post(URI uri) {
return new MockHttpServletRequestBuilder(HttpMethod.POST, uri);
}