这样的很简单,你需要引用两个com组件,和webbrowser控件,而且你的IE必须是6.0以上的
Microsoft.mshtml.dll,microsoft Html object libary.dll
之后你就可以通过如下方法来实现:
这是我实现的部分代码,你可以参考一下:
private void Form1_Load(object sender, System.EventArgs e)
{
if (exitflag==true)
{
Application.Exit();
}
else
{
this.txt_pwd.Text=m_strupwd;
this.axWebBrowser1.Navigate(this.m_strCardUserLogin,ref nullObject,ref nullObject, ref nullObject,ref nullObject);
this.label3.Text="正在连接请稍侯…………";
this.button4.Enabled=false;
}
/*newUrl="http://bizweb.sdeport.com"+response.GetResponseHeader("Location");
int start = newUrl.IndexOf("(");
int end =newUrl.IndexOf(")");
//得到每次传递网址的一个编号
Sid=newUrl.Substring(start,end-start+1);*/
}
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
this.LoginPage();
}
/// <summary>
/// 登陆内容填写/执行登陆事件
/// </summary>
/// <returns></returns>
public void LoginPage()
{
try
{
mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)axWebBrowser1.Document;
mshtml.HTMLInputElementClass textPassword = (mshtml.HTMLInputElementClass)doc.getElementById("textPassword");
textPassword.value=this.m_strupwd;
mshtml.HTMLInputElementClass btnLogin = (mshtml.HTMLInputElementClass)doc.getElementById("btnLogin");
btnLogin.click();
//flag=true;
}
catch(Exception ex)
{
//flag=false;
MsgBox("错误代码:407"+"\r\n"+ex.Message);
exitflag=true;
}
if (exitflag==true)
{
shutdown();
}
}
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Net;
这是需要引用的名称空间
原帖:http://topic.csdn.net/t/20061027/09/5112780.html
Microsoft.mshtml.dll,microsoft Html object libary.dll
之后你就可以通过如下方法来实现:
这是我实现的部分代码,你可以参考一下:
private void Form1_Load(object sender, System.EventArgs e)
{
if (exitflag==true)
{
Application.Exit();
}
else
{
this.txt_pwd.Text=m_strupwd;
this.axWebBrowser1.Navigate(this.m_strCardUserLogin,ref nullObject,ref nullObject, ref nullObject,ref nullObject);
this.label3.Text="正在连接请稍侯…………";
this.button4.Enabled=false;
}
/*newUrl="http://bizweb.sdeport.com"+response.GetResponseHeader("Location");
int start = newUrl.IndexOf("(");
int end =newUrl.IndexOf(")");
//得到每次传递网址的一个编号
Sid=newUrl.Substring(start,end-start+1);*/
}
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
this.LoginPage();
}
/// <summary>
/// 登陆内容填写/执行登陆事件
/// </summary>
/// <returns></returns>
public void LoginPage()
{
try
{
mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)axWebBrowser1.Document;
mshtml.HTMLInputElementClass textPassword = (mshtml.HTMLInputElementClass)doc.getElementById("textPassword");
textPassword.value=this.m_strupwd;
mshtml.HTMLInputElementClass btnLogin = (mshtml.HTMLInputElementClass)doc.getElementById("btnLogin");
btnLogin.click();
//flag=true;
}
catch(Exception ex)
{
//flag=false;
MsgBox("错误代码:407"+"\r\n"+ex.Message);
exitflag=true;
}
if (exitflag==true)
{
shutdown();
}
}
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Net;
这是需要引用的名称空间
原帖:http://topic.csdn.net/t/20061027/09/5112780.html
没有HTMLDocument 只有 HtmlDocument 。我也经常犯这样的错误,不知道你的是否是这种情况。