Java Code Examples for org.springframework.web.client.resttemplate#postForLocation()
The following examples show how to use
org.springframework.web.client.resttemplate#postForLocation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostController.java From Spring-Boot-Book with Apache License 2.0 | 5 votes |
@RequestMapping("/postForLocation") public URI postForLocation() { // 封装参数,千万不要替换为Map与HashMap,否则参数无法传递 MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>(); paramMap.add("name", "20180416"); paramMap.add("id", 4); RestTemplate client = restTemplateBuilder.build(); User user = new User(); user.setName("hongwei"); user.setId(6); URI response = client.postForLocation("http://localhost:8080/postuser", paramMap); return response; }
Example 2
Source File: PostTest.java From Spring-Boot-Book with Apache License 2.0 | 5 votes |
@Test public void postForLocation() { // 封装参数,千万不要替换为Map与HashMap,否则参数无法传递 MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>(); paramMap.add("name", "longzhonghua"); paramMap.add("id", 4); RestTemplate client = restTemplateBuilder.build(); URI response = client.postForLocation("http://localhost:8080/post",paramMap); System.out.println(response); }
Example 3
Source File: SampleAppIntegrationTest.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testSample() throws Exception { // Run Source app SpringApplicationBuilder sourceBuilder = new SpringApplicationBuilder(FunctionalSourceApplication.class) .resourceLoader(new PropertyRemovingResourceLoader("spring-cloud-gcp-pubsub-stream-binder-functional-sample-source")); sourceBuilder.run(); //Run Sink app SpringApplicationBuilder sinkBuilder = new SpringApplicationBuilder(FunctionalSinkApplication.class) .resourceLoader(new PropertyRemovingResourceLoader("spring-cloud-gcp-pubsub-stream-binder-functional-sample-sink")); sinkBuilder.run(); // Post message to Source over HTTP. MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); String message = "test message " + UUID.randomUUID(); map.add("messageBody", message); map.add("username", "integration-test-user"); RestTemplate restTemplate = new RestTemplate(); URI redirect = restTemplate.postForLocation("http://localhost:8080/postMessage", map); assertThat(redirect.toString()).isEqualTo("http://localhost:8080/index.html"); Awaitility.await().atMost(10, TimeUnit.SECONDS) .until(() -> this.output.getOut() .contains("New message received from integration-test-user: " + message)); }
Example 4
Source File: RestTemplateTest.java From spring-tutorials with Apache License 2.0 | 5 votes |
@Test public void test_postForLocation() throws URISyntaxException { RestTemplate restTemplate = new RestTemplate(); URI location = restTemplate.postForLocation(baseUrl, null); isTrue(location.equals(new URI("http://example.com"))); }
Example 5
Source File: MailService.java From expper with GNU General Public License v3.0 | 5 votes |
public void sendViaMailgunApi(EmailParams emailParams) { String apiUrl = jHipsterProperties.getMailgun().getApiUrl(); String apiKey = jHipsterProperties.getMailgun().getApiKey(); MultiValueMap<String, Object> vars = new LinkedMultiValueMap<>(); vars.add("from", jHipsterProperties.getMailgun().getFrom()); vars.add("to", emailParams.getTo()); vars.add("subject", emailParams.getSubject()); vars.add("html", emailParams.getContent()); RestTemplate restTemplate = new BasicAuthRestTemplate(MAILGUN_USER_NAME, apiKey); restTemplate.postForLocation(apiUrl, vars); log.debug("Email sent successfully."); }
Example 6
Source File: ExampleControllerIntegrationTests.java From salespoint with Apache License 2.0 | 3 votes |
@Test // #72 void usesUtf8ToDecodePayload() { RestTemplate template = new RestTemplate(); MultiValueMap<Object, Object> parameters = new LinkedMultiValueMap<>(); parameters.add("value", "äöü€"); template.postForLocation(String.format("http://localhost:%s/encoding", port), parameters); }