tags:

views:

50

answers:

1

I know that I can generate and send a post via HttpWebRequest, but I am wondering if it's possible to generate the post and return it to a web application so that it can perform the post.

In other words, I want the web application to call a method in my class library that generates the post request, but I want the web application to submit it. Is that possible?

EDIT:
I recognize that this sounds like a "WTF? Why would you want to do this?" so let me give some background. There is some fairly complex logic being used to build some of the the encrypted post values (some of which contain data the web application doesn't have access to). So to keep the web portion simple, we abstracted away the post generation. The problem now is that we need the calling application to be the one that actually makes the post.

Another clarification, I'd like to have the browser submit the request (i.e. as if the user filled out a form and submitted it).

+1  A: 

The request for a HttpWebRequest isn't submitted until you call GetResponse so it should be possible to pass the HttpWebRequest and call GetResponse from wherever you like, although i'm not sure why you would prefer to do it this way.

HttpWebRequest req = ClassLibrary.GetPostRequest();
HttpWebResponse res = req.GetResponse();
Chris Diver
I agree, in theory I think I should be able to do it. Any idea how I'd actually submit it from the calling web page though?
Sean Gough
`HttpWebRequest req = ClassLibrary.GetPostRequest();``HttpWebResponse res = req.GetResponse();`
Chris Diver
@Sean Gough: I'm not clear on whether you want the request submitted from the web browser or the web app (ie server).
Chris
From the browser, as if they'd filled out a form and submitted it themselves basically.
Sean Gough
In that case you will need to use JavaScript to either submit a form, or use Ajax to do it in the background.
Chris Diver
I just got to that same conclusion myself. Turns out the whole HttpRequest angle is not really applicable since I need the browser to do it. Ended up doing it in JavaScript.
Sean Gough