Capture webBrowser control response

孤人 提交于 2020-01-06 14:50:33

问题


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:

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!


回答1:


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
}



回答2:


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


来源:https://stackoverflow.com/questions/10212982/capture-webbrowser-control-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!