Android : j_spring_security_check resulted in 401 (Android)

on Tuesday, October 28, 2014


I am trying to login my API through spring security with rest template. I am able to login successfully in my web project but not with android app. I am trying to solve this issue for a long time but couldn't figure out.


Web code:



@Autowired
RestTemplate restTemplate;

MultiValueMap<String, String> loginMap = new LinkedMultiValueMap<String, String>();
loginMap.add("j_username", j_username);
loginMap.add("j_password", j_password);

HttpEntity<?> userEntity = new HttpEntity<Object>(loginMap, new HttpHeaders());

restTemplate.postForObject(PATH + "/j_spring_security_check", userEntity, String.class);


Android Code:



RestTemplate restTemplate = new RestTemplate();

MultiValueMap<String, String> loginMap = new LinkedMultiValueMap<String, String>();
loginMap.add("j_username", this.mEmail);
loginMap.add("j_password", this.mPassword);

HttpEntity<?> userEntity = new HttpEntity<Object>(loginMap, new HttpHeaders());
restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

restTemplate.postForObject(PATH + "/j_spring_security_check", userEntity, String.class);


Thanks


0 comments:

Post a Comment