Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process raw HTTP request content

I am doing an e-commerce solution in ASP.NET which uses PayPal's Website Payments Standard service. Together with that I use a service they offer (Payment Data Transfer) that sends you back order information after a user has completed a payment. The final thing I need to do is to parse the POST request from them and persist the info in it. The HTTP request's content is in this form :

SUCCESS
first_name=Jane+Doe
last_name=Smith
payment_status=Completed
payer_email=janedoesmith%40hotmail.com
payment_gross=3.99
mc_currency=USD
custom=For+the+purchase+of+the+rare+book+Green+Eggs+%26+Ham

Basically I want to parse this information and do something meaningful, like send it through e-mail or save it in DB. My question is what is the right approach to do parsing raw HTTP data in ASP.NET, not how the parsing itself is done.

like image 782
Slavo Avatar asked Aug 21 '08 15:08

Slavo


People also ask

What is raw HTTP request?

The Raw HTTP action sends a HTTP request to a web server. How the response is treated depends on the method, but in general the status code and the response headers are returned in variables defined as part of the page load options.

What are the 4 types of HTTP request methods?

The most commonly used HTTP request methods are GET, POST, PUT, PATCH, and DELETE. These are equivalent to the CRUD operations (create, read, update, and delete).

What is HTTP request content?

HTTP requests are messages sent by the client to initiate an action on the server. Their start-line contain three elements: An HTTP method, a verb (like GET , PUT or POST ) or a noun (like HEAD or OPTIONS ), that describes the action to be performed.


1 Answers

Something like this placed in your onload event.

if (Request.RequestType == "POST")
{
    using (StreamReader sr = new StreamReader(Request.InputStream))
    {
        if (sr.ReadLine() == "SUCCESS")
        {
            /* Do your parsing here */
        }
    }
}

Mind you that they might want some special sort of response to (ie; not your full webpage), so you might do something like this after you're done parsing.

Response.Clear();
Response.ContentType = "text/plain";
Response.Write("Thanks!");
Response.End();

Update: this should be done in a Generic Handler (.ashx) file in order to avoid a great deal of overhead from the page model. Check out this article for more information about .ashx files

like image 78
Markus Olsson Avatar answered Sep 27 '22 20:09

Markus Olsson