java - How to extract HTTP status code from the RestTemplate call to a URL? -


I am using 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

I'm mapping on 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;   

The question now is -

After attempting to remove the 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?

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 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.   

Use the methods that come back. This gives you access to the status line and header (and clearly to the body).

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -