Do a http form POST on external URL and redirect to it

I have an external vendor i want to redirect. For example, i am encrypting the current user info, and want to send that to the external vendor, so the user information is automatically populated on his website.

Everything works fine if i do that on the front end side using JS.

The problem i have is only my app server is whitelisted to the vendor. So i need to make the redirection happen on the backend.

I tried several method, and even with Guzzle HTTP, and it doesn’t redirect.

TO be clear, i am not looking for a simple redirect, it is a form post on external URL.

I went though this post, but the problem remain the same… Yii2 how to send form request to external url

Does anybody faced this issue?

Should it be done in-browser or should it be done purely on the backend part?

1 Like

Hi samdark
It should be done purely on the backend part, because the vendor whitelisted only our server…
I was even thiinking of have a service on the same server outside the app, that accepts the get parameters, than automatically POST submit the request. But a bit hacky…

Then what do you mean by “does not redirect”?

Sorry i maybe was not clear enough.

So the call $this->redirect from yii framework is to do a “GET” request that will go to another page.

But what i need is to do a POST request with parameters to an external page(external HTTP Post submit). And I can’t use Curl because I really need to land to the external page.

My Flow :
I have an yii2 webapp. A user is connected.
I want the user to go to an external website, and I don’t want him to type again all his information(first name, last name etc)
So we have an encryption key to communicate with the external website. So from the yii2 webapp, I encrypt all the parameters from the user like first name last name etc…
I do a http POST submit, where it goes to the external website. The external website analyze the parameters and decode it using an encryption key.
The user is now in the external website, with the values pre populated.

The form submit can’t be done with JS in the front end, because only yii app server is whitelisted in the external site, so it has to be done on the back end.

Impossible to do at server side: https://stackoverflow.com/questions/2604530/a-good-way-to-redirect-with-a-post-request

1 Like

I will talk to open the call to public :slight_smile: thanks for confirming Samdark! I really appreciate.