Search code examples
c#asp.netajaxhttpasp.net-core

Can server add/change body of http POST for redirect with new body?


I have to do this action for use payment service provider's form and add signature on server side. I can modify client and server.

Can I do this?

  1. client request —(POST, body: {"a":"1"})—> my_server
  2. my_server add new param "signature"
  3. my_server response —(3xx, body: {"a": "1", "signature": 354}, Location: https://psp.com)—> client
  4. client auto request on 3xx —(POST, body: {"a": "1", "signature": 354})—> https://psp.com

Is the the correct approach? What 3xx is appropriate for this action?


Solution

  • No. You cannot redirect with a body. A redirect doesn't do anything on its own. It simply tells the client that the page has moved or that they should simply see another page instead at this point. That's it. Response done.

    A web browser takes the initiative to then actually request that new URL contained in the Location header of the redirect response. However, it will always issue a GET request for the new URL, and as such, it will not "post" any data along with it.