开发者

WebRequest to POST data but what about hidden fields?

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;
    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜