Strange problems with the Spring RestTemplate in Android application
Posted
by
HarryCater
on Stack Overflow
See other posts from Stack Overflow
or by HarryCater
Published on 2012-12-17T17:00:52Z
Indexed on
2012/12/17
17:02 UTC
Read the original article
Hit count: 245
I begin to use RESTful api of the Spring Framework in my android client application. But I have encountered with problems when I tried to execute HTTP request via postForObject/postForEntity methods. Here is my code:
public String _URL = "https://noticemed.com/app/mobile/login";
public void BeginAuthorization(View view)
{
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> _entity = new HttpEntity<String>(requestHeaders);
RestTemplate templ = new RestTemplate();
templ.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
templ.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
ResponseEntity<String> _response = templ.postForEntity(_URL,_entity,String.class); //HERE APP CRASHES
String _body = _response.getBody();
And here is a stack trace in logcat after app crashing.
As you see there is no definite error message.
So the question what am I doing wrong? How to fix this? May there is other way to do it?
I really need a help. Thanks in advance!
© Stack Overflow or respective owner