views:

58

answers:

2

I'm not sure if I'm asking the right question.

We have a web app that we're trying to have a 3rd party POST to. We're creating a special landing page for them to which they can submit the data we need via POST.

I'm not sure how to respond to their request, which I assume I handle as an incoming HttpRequest. Do I process their data in PageLoad or some other event? Where/How is this data contained?

Do I have to use HttpListener or the ProcessRequest handler, or what?

Doing a search here or on Google turns up a lot of results on how to POST to another site, but can't seem to find a relevant site on how to be that "other" site and handle the incoming POST data.

Again, I'm not sure I'm asking this right.

EDIT: I found the Page.ProcessRequest Method in the MSDN library, but the Remarks say "You should not call this method"

Thanks!

A: 

Best would be to use an IHttpHandler, but it is possible to do what you want using a standard ASP.NET Page. Using PageLoad is fine, you have access to the Request and Response properties, which give you everything you need to process an HTTP request. For example, to obtain form parameters, you can use Request["input1"] to get the form input value (either query string, form post, or cookie) with the name "input1".

What is it you need to do in response to this post request? What sort of data do you need to return? Until that is answered, hard to help further.

Kirk Woll
Well, our app allows our own users to enter data. We would like a 3rd party to be able enter their own data into our site, instead of us entering data for them. Why do this? Because they collect a superset of the data we need on their own web app. This way, they POST to us only the subset of the data required for our web app. They will be merely passing to us data automatically instead of via our own form entry. Validation and sanitizing will of course be performed on this data.
Marc
@Marc, how are your users entering data currently, if not through POST?
Jon Hanna
@Marc, so a 3rd party is writing the HTML pages, but the `action` on the form element is pointing to your servers?
Kirk Woll
+1  A: 

You really need to look at the basics of ASP.NET. Even if this were a case where an IHttpHandler would be best-suited, I'd suggest using an .aspx page in this case as it's the best place to begin learning, and you can move to an IHttpHandler later on.

If the data is posted in application/x-www-form-urlencoded or multipart/form-data (the two formats used by forms on web pages - if they haven't told you what format they are using then it's probably one of those two), the Request.Form property (actually, a property of a property) will act as a dictionary into the data sent (e.g. if they have a field called "foo" then Request.Form["foo"] wll return the value of it as a string). Otherwise you'll want to use the Request.InputStream and read from that. This latter is a tiny bit more involved though.

Jon Hanna