打开页面时就提交,可以做一些自动登陆 还有SICLOGIN的测试代码

 
< HTML >
< head >
< title > Untitled Document </ title >
(1)自动提交表单:
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312">
</ head >
< script language =JavaScript>
    setTimeout( "document.form1.submit()" , 10000)
</ script >
< body bgcolor ="#FFFFFF" text ="#000000">
< form name ="form1" method ="post" action ="pp.ASP">
  < p >
   < input type ="text" name ="textfield">
  </ p >
  < p >
   < input type ="text" name ="textfield2">
  </ p >
</ form >
</ body >
</ html >
  
 
 
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Web;
using System.Threading;
using System.Collections;
using System.Configuration;
using mshtml;
namespace WebRequestToLogin
{
    public partial class Default : Form
    {
        public Default()
        {
            InitializeComponent();
        }
        int i = 0;
 
        private void Form1_Load( object sender, EventArgs e)
        {
            //string ResultMsg = string.Empty;
            // Login("rivern@tom.com", "feiyang", "");
            //return;
           // webBrowser1.Navigate("http://qqapp.qq.com/app/" + this.textBoxPhone.Text.Trim() + ".html#jump=http%3a%2f%2frc.qzone.qq.com%2f100654250%3fvia%3dQZSTORE.XX.HOME-HOT.PAGE2.SEQ6_10008_200");
 
            this .textBoxPhone.Text = "100654070" ;
 
            button2_Click_1(sender,e);
       
        }
 
 
        private void Login( string UserName, string UserPwd, string LoginUrl)
        {
       
            // 
            // TODO: 在此处添加代码以启动应用程序 
            // 
            string url = "http://www.kaixin001.com/login/login.php" ;
            //            <% 
            //            if request("aa")="zhuye" then session("ok")="ok" 
            //            if session("ok")="ok" then 
            //            response.write("登录") 
            //            else 
            //            response.write("没有登录") 
            //            end if 
            //            %> 
            string indata = "url=/home/&invisible_mode=0&email=" + UserName + "&password=" + UserPwd;
            string outdata = "" ;
            CookieContainer myCookieContainer = new CookieContainer ();
            //新建一个CookieContainer来存放Cookie集合 
            HttpWebRequest myHttpWebRequest = ( HttpWebRequest ) WebRequest .Create(url);
            //新建一个HttpWebRequest 
            myHttpWebRequest.ContentType = "application/x-www-form-urlencoded" ;
            myHttpWebRequest.ContentLength = indata.Length;
            myHttpWebRequest.Method = "POST" ;
            myHttpWebRequest.CookieContainer = myCookieContainer;
            //设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainer 
            Stream myRequestStream = myHttpWebRequest.GetRequestStream();
            StreamWriter myStreamWriter = new StreamWriter (myRequestStream, Encoding .Default);
            myStreamWriter.Write(indata);
            //把数据写入HttpWebRequest的Request流 
            myStreamWriter.Close();
            myRequestStream.Close();
            //关闭打开对象 
            HttpWebResponse myHttpWebResponse = ( HttpWebResponse )myHttpWebRequest.GetResponse();
            //新建一个HttpWebResponse 
            myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
            //获取一个包含url的Cookie集合的CookieCollection 
            Stream myResponseStream = myHttpWebResponse.GetResponseStream();
            StreamReader myStreamReader = new StreamReader (myResponseStream, Encoding .UTF8);
            outdata = myStreamReader.ReadToEnd();
            //把数据从HttpWebResponse的Response流中读出 
            myStreamReader.Close();
            myResponseStream.Close();
            Console .WriteLine(outdata);
            //显示"登录" 
 
            //拿到了Cookie,再进行请求就能直接读取到登录后的内容了 
            myHttpWebRequest = ( HttpWebRequest ) WebRequest .Create(url);
            myHttpWebRequest.CookieContainer = myCookieContainer; //* 
            //刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证 
            myHttpWebResponse = ( HttpWebResponse )myHttpWebRequest.GetResponse();
            myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
            myResponseStream = myHttpWebResponse.GetResponseStream();
            myStreamReader = new StreamReader (myResponseStream, Encoding .UTF8);
            outdata = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            Console .WriteLine(outdata);
            //再次显示"登录" 
            //如果把*行注释调,就显示"没有登录" 
  
        }
       
            private void Button2_Click( object sender, EventArgs e)
            {
              
                    try
                    {
                        string strhtml = string .Empty;
 
            
                        this .timerHLSet.Start();
                       // this.timerRef.Start();
                        MessageBox .Show( "启动任务成功!" );
                    }
                    catch ( Exception ex)
                    {
                        //
                    }
            }
 
        private void HtmlMsc()
        {
            try
            {
 
                webBrowser1.Navigate( "http://qqapp.qq.com/app/" + this .textBoxPhone.Text.Trim() + ".html#jump=http%3a%2f%2frc.qzone.qq.com%2f100654250%3fvia%3dQZSTORE.XX.HOME-HOT.PAGE2.SEQ6_10008_200" );
                System.Windows.Forms. HtmlDocument document = this .webBrowser1.Document;
              
                if (document == null )
                {
                    return ;
                }
                //document.All["mobile1"].SetAttribute("value", this.textBoxPhone.Text.Trim());            //用户名  
              
 
                //根据ID来自动点击CLICK
                webBrowser1.Document.GetElementById( "gotoapp-link" ).InvokeMember( "click" ); //当按钮是authZForm.submit()
 
                //根据标莶来点击
                //HtmlElementCollection Html = webBrowser1.Document.GetElementsByTagName("img");
                //foreach (HtmlElement h in Html)
                //{
                //    h.InvokeMember("click");
                //    this.webBrowser1.ScriptErrorsSuppressed = true;
                //    this.webBrowser1.Refresh();
                //}
                webBrowser1.Stop();
                this .labelNo.Text = "任务被执行" + i + "次" ;
                i++;
            }
            catch ( Exception ex)
            { }
        }
 
            private void notifyIcons_Click( object sender, EventArgs e)
            {
                this .Visible = true ;
 
                this .WindowState = FormWindowState .Normal;
 
                this .notifyIcons.Visible = false ;
 
            }
 
            private void Form1_SizeChanged( object sender, EventArgs e)
            {
                if ( this .WindowState == FormWindowState .Minimized)
                {
                    this .Hide();
                    this .notifyIcons.Visible = true ;
                }
            }
 
            private void timerHLSet_Tick( object sender, EventArgs e)
            {
                HtmlMsc();
            }
 
            private void timerRef_Tick( object sender, EventArgs e)
            {
                try
                {
                 
                    webBrowser1.Navigate( "http://m.tom.cn/appweb/163/download.jsp?id=1" );
                    this .webBrowser1.ScriptErrorsSuppressed = true ;
                    this .webBrowser1.Refresh();
                }
                catch ( Exception ex)
                {
 
                }
            }
 
            private void webBrowser1_Navigated( object sender, WebBrowserNavigatedEventArgs e)
            {
                IHTMLWindow2 win = ( IHTMLWindow2 )webBrowser1.Document.Window.DomWindow;
                string s = "window.alert = null;\r\nwindow.confirm = null;\r\nwindow.open = null;\r\nwindow.showModalDialog = null;" ;
                win.execScript(s, "javascript" );
 
 
 
            }
 
            private void webBrowser1_NewWindow( object sender, CancelEventArgs e)
            {
                e.Cancel = true ;
 
        
 
            }
 
            private void timerr_Tick( object sender, EventArgs e)
            {
                string strurl = null ;
                strurl = webBrowser1.Url.AbsoluteUri;
                string [] str = strurl.Split( '=' );
 
                foreach ( string s in str)
                {
                    if (s == "http://www.qq.com/?oauth_token" )
                        this .timerr.Stop();
                    break ;
                }
                string strurlx = str[1].ToString();
                string [] strx = strurlx.Split( '&' );
 
                MessageBox .Show(strx[0].ToString());
                MessageBox .Show(str[2].ToString());
            }
 
            private void button1_Click( object sender, EventArgs e)
            {
                try
                {
 
                    webBrowser1.Navigate( "http://qqapp.qq.com/app/" + this .textBoxPhone.Text.Trim()+ ".html#jump=http%3a%2f%2frc.qzone.qq.com%2f100654250%3fvia%3dQZSTORE.XX.HOME-HOT.PAGE2.SEQ6_10008_200" );
                   
                    System.Windows.Forms. HtmlDocument document = this .webBrowser1.Document;
 
                    if (document == null )
                    {
                        return ;
                    }
               
                    //document.All["mobile1"].SetAttribute("value", this.textBoxPhone.Text.Trim());            //用户名  
 
                    webBrowser1.Document.GetElementById( "gotoapp-link" ).InvokeMember( "click" ); //当按钮是authZForm.submit()
                    webBrowser1.Stop();
                }
                catch ( Exception ex)
                {
                    //if (!string.IsNullOrEmpty(ex.Message))
                    //    button1_Click(sender,e);
                }
 
              
            }
 
            private void herfclick( string url)
            {
                for ( int i = 0; i < webBrowser1.Document.All.Count; i++)
                {
                    if (webBrowser1.Document.All[i].TagName == "A" && webBrowser1.Document.All[i].GetAttribute( "href" ).ToString().Trim() == url)
                    {
                        webBrowser1.Document.All[i].InvokeMember( "click" ); //引发”CLICK”事件
                        break ;
                    }
                }
            }
 
            private void button2_Click_1( object sender, EventArgs e)
            {
                webBrowser1.Navigate( "http://ptlogin2.qq.com/jump?clientuin=309159808&clientkey=000151a4219f006858f02f51c30196d0c6e7f2518b441bf6d88812a22b4b11690f21a5c12a54bdd388d618793860942665ee01d80eb22358577984a0105b7a771b9376dc380681931f39749b0c619eb534f3dd70e3b7ac4890d6b22cc084b86fa51d881759375642fcb4b2894d002075&keyindex=9&pt_aid=549000912&u1=http%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone" );
               
            }
    }
}
  

转载于:https://www.cnblogs.com/oshoh/p/6970963.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值