L
L
lidiya112018-07-29 19:58:55
Java
lidiya11, 2018-07-29 19:58:55

Why 500 error when post request to server on Spring?

Please tell me why the error org.springframework.web.client.HttpServerErrorException: 500 appears when a post request is received, while the get request is processed normally (on the client it is written in the same way as post, only the getForObject method is used). The client is on android, the server is made using Spring mvc. What is wrong?
Customer:

public class postFinder extends AsyncTask<Void, Void, String> {
   @Override
    protected String doInBackground(Void... voids) {
       RestTemplate restTemplate = new RestTemplate();
       restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
       String id = restTemplate.postForObject(Constans.GET_MY_ID, ServisConnecter.id, String.class);
       return id;
    }
}

Server:
@RestController
@RequestMapping("/remind")
public class MyController {
    String ip;
    @Autowired
    public AdressServiceInterf adressServiceInterf;

    @RequestMapping(value = "get", method = RequestMethod.GET)
    @ResponseBody
    public long getUserId(HttpServletRequest request){
        ip=getClientIpAddr(request);
        return createMockAdresses(ip);
    }

    @RequestMapping(value = "getrand", method = RequestMethod.POST)
    @ResponseBody
    public String getRandomAdress(@RequestBody Long id){
         return "my id = " + id;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2018-12-16
kuzmin @sergueik

well, you don’t have a method for which the POST request is rooted, add it and get another response better than five hundred

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question