0

I have 2 spring boot based java app .

In one of the controller i am redirecting to call to second app but second app is also expecting some request headers. How can i add requestheaders to redirect uri.

public @ResponseBody ResponseEntity<?> testMethod(@RequestHeader("User-Agent") String userAgent){

HttpHeaders headers = new HttpHeaders();

// validating request .if success 

headers.set("test-header", "value");
URI uri = new URI("http://localhost:8083/test1");
headers.setLocation(uri);
return new ResponseEntity<String>(headers,HttpStatus.FOUND);
}

but in the second app i don't see headers coming in . Is there a way to redirect with http headers.

Please help me out.

  • try to set in your application.properties `server.use-forward-headers=true` – Glim Apr 19 '18 at 03:06
  • @Glim tried did not work i only see key :hostvalue :localhost:8083 key :connectionvalue :keep-alive key :upgrade-insecure-requestsvalue :1 key :user-agentvalue :Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 key :acceptvalue :text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 key :dntvalue :1 key :accept-encodingvalue :gzip, deflate, br key :accept-languagevalue :en-US,en;q=0.9,it;q=0.8,hi;q=0.7 key :cookievalue :_ga=GA1.1.1236633073.1520536474 – vaibhav srivastava Apr 19 '18 at 04:23
  • Possible duplicate of [How to set an "Accept:" header on Spring RestTemplate request?](https://stackoverflow.com/questions/19238715/how-to-set-an-accept-header-on-spring-resttemplate-request) – Mehraj Malik Apr 19 '18 at 04:47
  • @MehrajMalik , that will work fine with RestTemplate but I am redirecting the call to different app. So , both the scenarios are different . – vaibhav srivastava Apr 19 '18 at 05:32
  • use cookie or query params instead https://stackoverflow.com/questions/41523670/spring-mvc-redirect-with-custom-http-headers – codebrane Apr 19 '18 at 11:07

0 Answers0