static void Main()
{
Application.Run(new Form1());
}
private void Navigate(string url)
{
object refUrl = url;
axWebBrowser1.Navigate2(ref refUrl, ref _Null, ref _Null, ref _Null, ref _Null);
} private void Form1_Load(object sender, System.EventArgs e)
{
axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(axWebBrowser1_NavigateComplete2);
}
private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
if(e.uRL.ToString() == "http://www.163.com/")
{
//提取的网页文档对象
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;
//需要提交的Form
mshtml.IHTMLFormElement f1 =(mshtml.IHTMLFormElement)doc.all.item ("loginvip",0);
//需要填写的文本框(u是该网页的登录名的文本框ID)
mshtml.IHTMLElement Element1 = (mshtml.IHTMLElement)doc.all.item("username", 0);
Element1.innerText = "yy_1998.";
mshtml.IHTMLElement Element2 = (mshtml.IHTMLElement)doc.all.item("password", 0);
Element2.innerText="198278";
//提交Form
((mshtml.IHTMLFormElement)(f1)).submit();
//点击页面中的按钮
mshtml.IHTMLElement Element = (mshtml.IHTMLElement)doc.all.item("submit", 0);
Element.click();
}
} private void button1_Click(object sender, System.EventArgs e)
{
Navigate("http://www.163.com/");
}
}
}
{
Application.Run(new Form1());
}
private void Navigate(string url)
{
object refUrl = url;
axWebBrowser1.Navigate2(ref refUrl, ref _Null, ref _Null, ref _Null, ref _Null);
} private void Form1_Load(object sender, System.EventArgs e)
{
axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(axWebBrowser1_NavigateComplete2);
}
private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
if(e.uRL.ToString() == "http://www.163.com/")
{
//提取的网页文档对象
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;
//需要提交的Form
mshtml.IHTMLFormElement f1 =(mshtml.IHTMLFormElement)doc.all.item ("loginvip",0);
//需要填写的文本框(u是该网页的登录名的文本框ID)
mshtml.IHTMLElement Element1 = (mshtml.IHTMLElement)doc.all.item("username", 0);
Element1.innerText = "yy_1998.";
mshtml.IHTMLElement Element2 = (mshtml.IHTMLElement)doc.all.item("password", 0);
Element2.innerText="198278";
//提交Form
((mshtml.IHTMLFormElement)(f1)).submit();
//点击页面中的按钮
mshtml.IHTMLElement Element = (mshtml.IHTMLElement)doc.all.item("submit", 0);
Element.click();
}
} private void button1_Click(object sender, System.EventArgs e)
{
Navigate("http://www.163.com/");
}
}
}
HttpWebResponse webResponse;
Stream getStream;
StreamReader streamReader;
string getString = ""; string httpAddress = "";
httpAddress = requestUrl; httpWebRequest = (HttpWebRequest)WebRequest.Create( httpAddress );
httpWebRequest.Method = "Get";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Referer = "";
httpWebRequest.CookieContainer = CookieUtil.CookieContainer;
httpWebRequest.Timeout = int.MaxValue; // if( httpWebRequest.HaveResponse )
// {
webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
// CookieUtil.SetCookie( webResponse.GetResponseHeader( "Set-Cookie" ) ); getStream = webResponse.GetResponseStream(); streamReader = new StreamReader( getStream, System.Text.Encoding.Default );
string lineStr = "";
while( ( lineStr=streamReader.ReadLine()) != null )
getString += lineStr;
streamReader.Close();
getStream.Close();
// } return getString;
httpWebRequest.Timeout = int.MaxValue;
// httpWebRequest.CookieContainer.Add( CookieUtil.BuildCookieCollection() );
string postData = "";
byte[] byteRequest = System.Text.Encoding.Default.GetBytes(postData);
// Set the content type of the data being posted.
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Method = "Post";
其中postData的字符串可由你截HTTP数据包可得,
基本上就是你网页提交的一些数据信息