捕获webBrowser控件响应

时间:2012-04-18 15:40:50

标签: c# webbrowser-control desktop-application

我正在使用C#中的webbrowser控件为我们的桌面应用程序通过网关运行信用卡。

简单地说,我正在加载页面加载页面:

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");


}

(出于安全原因,所有引用都已更改)

该页面如下所示:

Portal

我的问题是,如何点击“处理”按钮后如何获取响应,然后关闭表单?我需要知道它是否得到批准以及其他信息。

我无法控制按钮,因此我不确定如何捕获响应。

再次感谢!

2 个答案:

答案 0 :(得分:2)

您似乎需要订阅DocumentCompleted事件并通过Document,DocumentText或DocumentStream处理响应。

然后根据输出结果适当地做出反应。例如:

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
}

答案 1 :(得分:0)

在表单中,您可以创建一个公共方法,以便从您调用表单的位置获取可以访问的信息。您可以在dialogResult == DialogResult.OK上调用此方法,如下所示:

        object your_info;

        Form1 form1 = new Form1();
        if (form1.DialogResult == DialogResult.OK)
        {
            your_info = form1.getInfo();
        }