I am trying to make authorization through 4kkvar and at the moment when I have to redirect this page to confirm authorization I just get back the html of the page to which I should be redirected. How do I get to that page from the code?

public void authenticate() throws IOException { String url = "https://foursquare.com/oauth2/authenticate?response_type=code&redirect_uri=http://localhost:8080/4sqr/callback_url&client_id=1DUHD3H1DGL5*********NFSLRDLR"; HttpClient httpClient = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(url); HttpResponse response = httpClient.execute(post); HttpEntity entity = response.getEntity(); String content = EntityUtils.toString(entity); // здесь просто html той страницы на которую должно было бы перекинуть System.out.println(content); } 
  • one
    Is it a standard Apache HttpClient? - Mikhail Vaysman
  • @MikhailVaysman yes. I suspect that this should not work. Then interests how correctly to cause this rekvest? - raviga

1 answer 1

All right, you using HttpClient downloaded the contents of the url and sent to the user. And you need to redirect the user to this url :

 @RequestMapping(method = RequestMethod.GET) public String authenticate() { String url = "https://foursquare.com/oauth2/authenticate?response_type=code&redirect_uri=http://localhost:8080/4sqr/callback_url&client_id=1DUHD3H1DGL5*********NFSLRDLR"; return "redirect:" + url; } 
  • This is out of the controller, as I understand it, right? - raviga
  • Yes, you understand correctly. - Sergey Gornostaev
  • Got it. Thank. But why this standard of the redirect: prefix does not work redirect: and just returns a condensed string. - raviga
  • one
    everything. made via HttpServletResponse.sendRedirect() . Works. Thank. - raviga