Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("name", "xx");
map.add("password", "xx");
restTemplate.postForObject("URL", map, Response.class);
But it doesn't work. I want to send data into bitstamp api.
EDIT: My spring bean seems:
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
EDIT 2: My code seems
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON);// or any other
HttpHeaders headers = new HttpHeaders();
headers.setAccept(acceptableMediaTypes);
HttpEntity<String> requestEntity = new HttpEntity<String>("key=XX&nonce=XX&signature=XX", headers);
ResponseEntity<AccountBalance> responseEntity = restTemplate.exchange(
"https://www.bitstamp.net/api/balance/", HttpMethod.POST, requestEntity, AccountBalance.class);
Response is now: Missing key, signature and nonce parameters
But it should be: API key not found
–
–
–
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON);// or any other
HttpHeaders headers = new HttpHeaders();
headers.setAccept(acceptableMediaTypes);
HttpEntity<String> requestEntity = new HttpEntity<String>("name=XX&password=XX",headers);
ResponseEntity<Response> responseEntity = restTemplate.exchange("URL", HttpMethod.POST, requestEntity, Response.class);
–
–
–
It works now, thank you all :-)
MultiValueMap<String, String> body = new LinkedMultiValueMap<String, String>();
body.add("key", "XXX");
body.add("nonce", "XX");
body.add("signature", "XX");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<?> requestEntity = new HttpEntity<Object>(body, headers);
ResponseEntity<AccountBalance> responseEntity = restTemplate.exchange(bitstampBalanceUrl, HttpMethod.POST,
requestEntity, AccountBalance.class);
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.