I need help with sending POST data to an outside website and making the user’s browser go to that site. Right now I’m using HTTP client libraries to send the data, but the user stays on my page instead of being taken to the external site.
I want the user to end up on the payment page after I send the required parameters. Here’s what I’m working with:
try {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost request = new HttpPost("https://checkout.example.com/process");
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("amount", "750"));
params.add(new BasicNameValuePair("orderId", "12345"));
request.setEntity(new UrlEncodedFormEntity(params));
CloseableHttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() == 200) {
// User should be redirected to external payment site here
// But they stay on current page
}
response.close();
client.close();
} catch (IOException e) {
e.printStackTrace();
}
How can I make the browser actually navigate to the external URL after posting the form data?