3

Warning:
This question is NOT about How to post TO a Web Api, is How to post FROM Web Api.

Scenario:

My question is related to the comments of the answer of Darin Dimitrov in: How to Redirect in ASPNET Web API

and is seems to be a duplicated for: Response.Redirect which POSTs data to another URL in ASP.NET but take in consideration that the question is already old (2008) and I'm looking for answer that maybe WebApi is up to date.

Using Visual Studio 2012 Web Api 2.1

I've get from data in my application (is a web api) trough a POST method in a controller. So far so good. Now I want to post this data (with some changes) to an external site that accepts my data (this is validated and works).

For this process I've tried two methods:

  1. Make a string with a basic form that submit with a "onload" event with javascript.
    From (Response.Redirect which POSTs data to another URL in ASP.NET). This is working, and this is how I'm using it, but maybe can be replaced with some better approach.

  2. With an HTTPClient using client.PostAsync . I could also work with this, but I don't want show the response to the user, I want to redirect him. Maybe can be this adapted to make a redirect?

Question:

How do I redirect sending Post variables without using the "onload" workaround or adapting the "HttpClient" to make a post-redirection without waiting for response ?

Consideration: I don't post any code because implementations of my two options are already easy and I don't have any trouble with them.

Community
  • 1
  • 1
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
  • 1
    I think the options you have explored (redirecting via client-side form with onLoad submission, or server-side async redirection) are the only viable methods if you want to modify the POST data before the redirect. If you didn't need to alter the data, you could issue a 307 response to the client with the external API in the Location header (which should redirect the POST request), but not all browsers respond to 307 responses correctly. – Rudism Nov 11 '14 at 17:05
  • Thanks Rudism, I hope you are wrong... :( – Leandro Bardelli Nov 11 '14 at 17:07
  • 1
    This is still a requirement in 2018 and still no way that I can find of doing it without using any of the above mentioned hacks. – Neville May 17 '18 at 15:13

0 Answers0