tags:

views:

25

answers:

1

Hi, I need to essentially POST some hidden fields to a page, which i need to load in the browser window.

This is for the SagePay forms integration as per page 6: http://www.docstoc.com/docs/10745827/Sage-Pay-Form-Protocol-and-Integration-Guidelines

I am already using WebRequest to create the POST but how do I send the 4 hidden fields they require?

Also, how do I then load the returned html into the browser; this html is from SagePay where the customer enters their credit card details?

public string SendRequest(string url, string postData)
    {
        var uri = new Uri(url);
        var request = WebRequest.Create(uri);
        var encoding = new UTF8Encoding();
        var requestData = encoding.GetBytes(postData);

        request.ContentType = "application/x-www-form-urlencoded";
        request.Method = "POST";
        request.Timeout = (300 * 1000); //TODO: Move timeout to config
        request.ContentLength = requestData.Length;

        using (var stream = request.GetRequestStream())
        {
            stream.Write(requestData, 0, requestData.Length);
        }

        var response = request.GetResponse();

        string result;

        using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
        {
            result = reader.ReadToEnd();
        }

        return result;
    }
+1  A: 

Just add the 4 hidden fields into the postData string. This can be done on the fly in this method, or in the request.

The "hidden" aspect is only hidden in terms of the GUI in the browser.

Reed Copsey
N00b
@Noob: Look at page 41 - it describes how to make this work.
Reed Copsey
@Reed Copsey: I think what page 41 shows is for the option Basket key to recreate the shopping cart of the SagePay pages, but this isn't what I am referring to above.
N00b
@N00b: Well, I would recommend looking through their SDK for a sample encoding. Once you know how to encode, just add it to the post string -
Reed Copsey
Their integration kit is a joke, they create a form with the hidden fields in memory, assign it to a string and then to a label on the page. It's just not that useful.
N00b
@N00b: I'd recommend asking a (different) question specific to Sage, then, and hope somebody else knows their system. I don't have a way to decipher and test their stuff for you ;) Encoding details for the crypt parameter are really outside of the scope of this question - which I answered above. It has nothing to do with hidden fields.
Reed Copsey
Thats very true, for the question I asked originally I have set yours as the answer.
N00b