本文整理了Java中org.springframework.web.client.RestTemplate.postForLocation
方法的一些代码示例,展示了RestTemplate.postForLocation
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestTemplate.postForLocation
方法的具体详情如下:
包路径:org.springframework.web.client.RestTemplate
类名称:RestTemplate
方法名:postForLocation
暂无
代码示例来源:origin: spring-projects/spring-framework
@Test
public void multipart() throws UnsupportedEncodingException {
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("name 1", "value 1");
parts.add("name 2", "value 2+1");
parts.add("name 2", "value 2+2");
Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
parts.add("logo", logo);
template.postForLocation(baseUrl + "/multipart", parts);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void form() throws UnsupportedEncodingException {
MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
form.add("name 1", "value 1");
form.add("name 2", "value 2+1");
form.add("name 2", "value 2+2");
template.postForLocation(baseUrl + "/form", form);
}
代码示例来源:origin: spring-projects/spring-framework
private void testCreate(String url, String basename) {
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("json-data", new HttpEntity<>(new TestData(basename)));
parts.add("file-data", new ClassPathResource("logo.jpg", getClass()));
parts.add("empty-data", new HttpEntity<>(new byte[0])); // SPR-12860
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType("application", "octet-stream", StandardCharsets.ISO_8859_1));
parts.add("iso-8859-1-data", new HttpEntity<>(new byte[] {(byte) 0xC4}, headers)); // SPR-13096
URI location = restTemplate.postForLocation(url, parts);
assertEquals("http://localhost:8080/test/" + basename + "/logo.jpg", location.toString());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void postForLocation() throws URISyntaxException {
URI location = template.postForLocation(baseUrl + "/{method}", helloWorld, "post");
assertEquals("Invalid location", new URI(baseUrl + "/post/1"), location);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void postForLocationEntity() throws URISyntaxException {
HttpHeaders entityHeaders = new HttpHeaders();
entityHeaders.setContentType(new MediaType("text", "plain", StandardCharsets.ISO_8859_1));
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
URI location = template.postForLocation(baseUrl + "/{method}", entity, "post");
assertEquals("Invalid location", new URI(baseUrl + "/post/1"), location);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void partListBinding() {
PartListBean bean = new PartListBean();
partListServlet.setBean(bean);
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("partList", "first value");
parts.add("partList", "second value");
Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
parts.add("partList", logo);
template.postForLocation(baseUrl + "/partlist", parts);
assertNotNull(bean.getPartList());
assertEquals(parts.get("partList").size(), bean.getPartList().size());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void partsBinding() {
PartsBean bean = new PartsBean();
partsServlet.setBean(bean);
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
Resource firstPart = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
parts.add("firstPart", firstPart);
parts.add("secondPart", "secondValue");
template.postForLocation(baseUrl + "/parts", parts);
assertNotNull(bean.getFirstPart());
assertNotNull(bean.getSecondPart());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void postForLocationEntityContentType() throws Exception {
mockSentRequest(POST, "http://example.com");
mockTextPlainHttpMessageConverter();
mockResponseStatus(HttpStatus.OK);
String helloWorld = "Hello World";
HttpHeaders responseHeaders = new HttpHeaders();
URI expected = new URI("http://example.com/hotels");
responseHeaders.setLocation(expected);
given(response.getHeaders()).willReturn(responseHeaders);
HttpHeaders entityHeaders = new HttpHeaders();
entityHeaders.setContentType(MediaType.TEXT_PLAIN);
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
URI result = template.postForLocation("http://example.com", entity);
assertEquals("Invalid POST result", expected, result);
verify(response).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void postForLocationEntityCustomHeader() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
mockSentRequest(POST, "http://example.com", requestHeaders);
mockTextPlainHttpMessageConverter();
mockResponseStatus(HttpStatus.OK);
HttpHeaders responseHeaders = new HttpHeaders();
URI expected = new URI("http://example.com/hotels");
responseHeaders.setLocation(expected);
given(response.getHeaders()).willReturn(responseHeaders);
HttpHeaders entityHeaders = new HttpHeaders();
entityHeaders.set("MyHeader", "MyValue");
HttpEntity<String> entity = new HttpEntity<>("Hello World", entityHeaders);
URI result = template.postForLocation("http://example.com", entity);
assertEquals("Invalid POST result", expected, result);
assertEquals("No custom header set", "MyValue", requestHeaders.getFirst("MyHeader"));
verify(response).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void postForLocationNull() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
mockSentRequest(POST, "http://example.com", requestHeaders);
mockResponseStatus(HttpStatus.OK);
template.postForLocation("http://example.com", null);
assertEquals("Invalid content length", 0, requestHeaders.getContentLength());
verify(response).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void postForLocation() throws Exception {
mockSentRequest(POST, "http://example.com");
mockTextPlainHttpMessageConverter();
mockResponseStatus(HttpStatus.OK);
String helloWorld = "Hello World";
HttpHeaders responseHeaders = new HttpHeaders();
URI expected = new URI("http://example.com/hotels");
responseHeaders.setLocation(expected);
given(response.getHeaders()).willReturn(responseHeaders);
URI result = template.postForLocation("http://example.com", helloWorld);
assertEquals("Invalid POST result", expected, result);
verify(response).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void postForLocationNoLocation() throws Exception {
mockSentRequest(POST, "http://example.com");
mockTextPlainHttpMessageConverter();
mockResponseStatus(HttpStatus.OK);
URI result = template.postForLocation("http://example.com", "Hello World");
assertNull("Invalid POST result", result);
verify(response).close();
}
代码示例来源:origin: apache/servicecomb-java-chassis
@Override
public URI postForLocation(String url, Object request, Object... urlVariables) throws RestClientException {
return getRestTemplate(url).postForLocation(url, request, urlVariables);
}
代码示例来源:origin: apache/servicecomb-java-chassis
@Override
public URI postForLocation(URI url, Object request) throws RestClientException {
return getRestTemplate(url).postForLocation(url, request);
}
代码示例来源:origin: apache/servicecomb-java-chassis
@Override
public URI postForLocation(String url, Object request, Map<String, ?> urlVariables) throws RestClientException {
return getRestTemplate(url).postForLocation(url, request, urlVariables);
}
代码示例来源:origin: org.motechproject/motech-http-agent
@Override
public void execute(RestTemplate restTemplate, String url, Object request) {
restTemplate.postForLocation(url, request);
}
},
代码示例来源:origin: imalexyang/ExamStack
private void postAnswerSheet(String uri, Object body) {
try {
restTemplate.postForLocation(uri, body);
} catch (RestClientException e) {
LOGGER.error("Received exception:", e);
}
}
代码示例来源:origin: com.julienvey.trello/trello-java-wrapper
@Override
public URI postForLocation(String url, Object object, String... params) {
try {
return restTemplate.postForLocation(url, object, params);
} catch (RestClientException e) {
throw new TrelloHttpException(e);
}
}
代码示例来源:origin: ConsenSys/IPFS-Store
@Override
public void createIndex(String index) throws IPFSStoreException {
try {
log.debug("createIndex [indexName={}]", index);
restTemplate.postForLocation(
this.endpoint + BASE_API_PATH + CREATE_INDEX_API_PATH + "/" + index,
HttpEntity.EMPTY);
log.debug("Index [indexName={}] created !", index);
} catch (HttpClientErrorException ex) {
throw handleHTTPExceptiion(ex);
}
}
代码示例来源:origin: org.springframework.social/spring-social-google
@Override
public void clearCompletedTasks(TaskList taskList) {
notNull(taskList.getId());
restTemplate.postForLocation(TASKS_URL + taskList.getId() + "/clear",
null);
}
}
内容来源于网络,如有侵权,请联系作者删除!