Can a POST request be redirected as another GET request

660 Views Asked by At

I am working on a react application, where there is a need to send the object parameters inside a body because of confidentiality. So I am making a POST request from the react app client-side to the backend server like this

axios
  .post('htps://java.backend.xyz/path1', {
    data: password,
  })
  .catch(function (error) {
    handle(error);
  });

After making this POST request there is a preflight request with "method = OPTIONS" and "URL= 'htps://java.backend.xyz/path1'"...to which java-backend-server responds with status_code=200.

After the above preflight request, java-backend-server addresses the POST request and instead of sending a response the java-backend-server respond with a GET request (i.e redirect) as for example:

https://express-app.xyz/path2?query_para1=abc&query_param2=123, requestMethod=GET

And in response to the above GET request, the express app responds with status_code=200

But immediately after this GET request, there is a preflight request with request Method=OPTIONS and having the same URL as above i.e

https://express-app.xyz/path2?query_para1=abc&query_param2=123, requestMethod=OPTIONS

and for this above OPTIONS request express server responds with a status_code=204 which means that the client doesn't need to navigate away from its current page...this is something prohibiting my app to make a final redirect i.e after the backend server responds with a GET request, my react app is not able to make a redirect even search engine does not update the redirect URL which is

https://express-app.xyz/path2?query_para1=abc&query_param2=123

So, here Is this even possible? I am assuming that the preflight request after the GET request prohibits the client side to be able to make a final redirect. Can someone please help me with this scenario

1

There are 1 best solutions below

7
On

I am not sure if I understand your problem correctly but what you can do is send a post response which will which will indicate client to redirect to specific location. This can be achieved by sending response with status code 302 and location in header (location:redirect_url)

For more info :- https://en.m.wikipedia.org/wiki/HTTP_302