Capture webBrowser control response
Asked Answered
C

2

0

I am using the webbrowser control in C# for our desktop application to run a credit card through a gateway.

Simply, I'm loading the page on the load of the form:

public Form1()
{
  InitializeComponent();

  webBrowser1.Url = new Uri("https://paymentgateway.com/hosted.aspx?" +
                            "Username=dddd" +
                            "&Password=dddd" +
                            "&MerchantKey=5159" +
                            "&BillingAddress1=123 some street" +
                            "&BillingCity=Somewhere" +
                            "&BillingState=SC" +
                            "&BillingZip=39399" +
                            "&CustomerName=me" +
                            "&Amount=392.00" +
                            "&InvNum=123567" +
                            "&AccountNumber=0133333" +
                            "&CustomerId=0199999");


}

(all references changed for security reasons)

The page looks something like this:

Portal

My question is, how do I grab the response once the Process button has been clicked and then close out the form? I need to know if it was approved and the rest of the information from that point.

I don't have control over the button so I'm not sure how to capture the response.

Thanks again!

Catanzaro answered 18/4, 2012 at 15:40 Comment(0)
A
2

It seems that you need to subscribe to the DocumentCompleted event and handle the response there via Document, DocumentText or DocumentStream.

You would then react appropriately depending on what the output is. For example:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
  HtmlDocument document =  webBrowser1.Document;
  //now use any of the methods exposed by HtmlDocument to parse the output
}
Amain answered 18/4, 2012 at 15:55 Comment(1)
I am getting all HTML related things in "document" element but I was unable to get the response. ex:- I call a service. In completed event I need to know the response data for that service(we can see that response in fiddler in TextView tab). How can I get that response details.Tenner
L
0

In your form you can create a public method to get the information that you can have access from where you call the form. You can call this method on a dialogResult == DialogResult.OK, like this:

        object your_info;

        Form1 form1 = new Form1();
        if (form1.DialogResult == DialogResult.OK)
        {
            your_info = form1.getInfo();
        }
Lymphatic answered 18/4, 2012 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.