java - How to extract HTTP status code from the RestTemplate call to a URL? -
 I am using   I'm mapping on   The question now is -    After attempting to remove the    Update: -     This is what I have tried to do and I am able to get back feedback and status codes too. But do I always need to set the     Use the methods that come back. This gives you access to the status line and header (and clearly to the body).    RestTemplate  to call an HTTP call for my service A simple JSON response gives me that I do not need to parse that JSON. I   String.class  and the actual  JSON response < / Code> returning. As a string   
 RestTemplate restTemplate = New RestTemplate (); String response = restTemplate.getForObject (url, String.class); Return feedback;    HTTP status code  after hitting the URL I am using HTTP from the above code How can I remove the status code? Do I need to make any changes in the way I'm doing this now?   HttpHeaders  and  unit  objects as below?   
 RestTemplate restTemplate = New RestTemplate (); // And for my use case do I need this JSON media type? HTTP header header = new HTTP header (); headers.setContentType (MediaType.APPLICATION_JSON); // my entity httpTPNT & lt; Object & gt; set on. Unit = new HttpEntity & lt; Object & gt; (Header); ResponseEntity & LT; String & gt; Out = restTemplate.exchange (URL, HttpMethod.GET, Entity, String.class); Println (out.getBody ()); Println (out.getStatusCode ()); A couple of questions - do I need to call  MediaType.APPLICATION_JSON  because I am just calling the URL that returns a response, it can either return JSON or XML or simple string.   
 
Comments
Post a Comment