Post and redirect FROM Web Api

青春壹個敷衍的年華 提交于 2019-12-01 21:57:07

问题


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.

来源:https://stackoverflow.com/questions/26868821/post-and-redirect-from-web-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!