views:

247

answers:

1

Is it possible to post to a form from pure code behind in ASP.NET? Basically I need to simulate a Response.Redirect() but do so with a POST instead of a GET and also set a couple Request parameters. This would all be happening in the ProcessRequest method on a HTTP handler.

Notes: I realize that Response.Redirect really just throws the http 302 item moved code back to the browser, I'm guessing that the above isn't possible and that there are better ways to do what I'm talking about using a separate page and a form with the action set to the intended target. It would be awesome if HttpContext has some mythical methods I don't know about though.

EDIT:

Ok, so figured out a work around, basically Response.Write()ing a bunch of html and javascript from the IHttpHandler. This then does the post and simulates having an intermediate page to do the post (but keeps as much code as possible within the handler).

A: 

Certainly. You can use the WebRequest class in the handler to do the POST. Call that from your handler and you should be fine.

John Saunders
Would you Response.Write the results of the WebRequest call in the handler? The issue is that I need the browser to seamlessly end up on the next page.
Will Charczuk
Response.Write or something of the sort, yes. In some complex cases, you might need to Write a page containing JavaScript that would do some processing, then set window.location, but in general, the handler will be requested by the browser, and will produce the desired result output.
John Saunders