WebResponse for HttpResponseBase. Is it possible?

In the controller action, I manually submit the form to the remote URL using WebRequest. I successfully get a WebResponse containing the html display page. I would like to β€œinsert” this answer as a response (such as an HttpResponseBase) action. An action usually returns an ActionResult, so how can I complete my controller action so that the result of WebResponse is the result?

Note: Url in the browser should also be the response URL.

Update : here is the goal. This is on the PayPal verification page. Instead of having a form with all the hidden fields of the basket and a submit button, in my opinion, I need a simple check button related to one of my actions. In this step, I will prepare WebRequest with the form and submit it to paypal. Performing this action also allows me to store the inactivated order in the database table, so when the order confirmation arrives, I can compare it with the saved order and activate it.

Solution : thanks to those who answered, indicating that it would not be possible to redirect using POST. It seems like I don't have to redirect to paypal using POST. Instead, I can create a URL with all the cart data in the query string and redirect to it. Performing this action using the controller action method allows me to store pending order in the database.

thanks

+4
source share
2 answers

If you want the contents of the WebRequest response to be sent back in response from the action of your controller, you can do something similar in your action method:

WebRequest req = WebRequest.Create("http://www.google.com"); WebResponse res = req.GetResponse(); StreamReader sr = new StreamReader(res.GetResponseStream()); ContentResult cr = new ContentResult(); cr.Content = sr.ReadToEnd(); return cr; 

this is even more eloquent:

 WebRequest req = WebRequest.Create("http://www.google.com"); WebResponse res = req.GetResponse(); FileStreamResult fsr = new FileStreamResult(res.GetResponseStream(),res.ContentType); return fsr; 
+4
source

There is no direct way to do this. I do not know much about ASp.NET. ARe you say your ASP.net page is making an HTTP request to the remote site and returning a response, and you want this response to become an HTTPResponseBase? What do you want to do after that?

See the next SO thread on a similar topic ... How do I make fun of HttpResponseBase.End ()?

0
source

All Articles