1

I am working on a project that uses Spring MVC, and one of the requirement involves sending request to an external services to handle some transactions. The problem now is the external services only takes POST method, and I've looked everywhere and could not find a way to forward user to external site as a POST request(similar to form submit).

What we are trying to do:

1) My Controller will receives request and execute some backend thing and construct some parameters to pass on.

2) *Send request to external service via HTTP POST method with some parameters. (note. User's browser will show URL of the external site.)

I've looked into different return types for Spring MVC and could not find anything that fits.

Any advice would be greatly appreciated.

Thanks!

3 Answers 3

2

You can use the Apache HttpComponents library to send HTTP requests from you controller. It's easy to use, and there's plenty of documentation and examples.

Sign up to request clarification or add additional context in comments.

Comments

1

Supposed that this is not an issue related the Spring MVC. That's the same solution Which you try to implement such operations in Servlet I think.

First of all, this external site should be an async service and you neednt get the response from it, right? If yes, i think the simplest solution is that you can new URLConnection within your Servlet or Controller, construct the params and set the POST method, and then send out the request. After that, you can response to your local page as you like.

The second solution, a dummy JSP page is needed. The page will post a form to external service and redirect to the target page as you needed. No matter you use a javascript or not, I think the user will see a refresh on the browser.

Comments

1

You won't be able to redirect as that implies a GET.

Since your client is using a web browser, it should be possible to return an HTML document with a form, and then to submit that form (with a method attribute of POST) when the page has loaded.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.