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

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

  1. 判断手机端用户打开页面时是android还是ios,并将判断结果通过ajax返回给url接口,传递回去

    首先判断页面是android还是ios,然后利用ajax将结果通过接口url返回回去,记录到log日志中,以统计android和ios用户访问该页面的数量(数据统计) <script type= ...

  2. 获取打开页面时的当前时间(yyyy-MM-dd hh:mm:ss)

    Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...

  3. 打开powerDesigner时,创建table对应的自动生成sql语句没有注释

    在创建pdm时由于需要在name列填写的是以后要在表中创建的注释信息,comment中则写的说明信息字数比较多.默认情况下在生成建表sql时不能将name生成注释信息,进行如下设置可以讲name生成注 ...

  4. 【转】iframe和父页,window.open打开页面之间的引用

    [转]iframe和父页,window.open打开页面之间的引用 iframe和父页,window.open打开页面和被打开页面之间的关系可以通过下面的对象获取到 1)通过iframe加载的,在if ...

  5. 怎么隐藏 iOS Safari 打开网页时的地址栏和工具栏探索

    先来看一张截图 红色框处就是用手机浏览器打开页面时,自动显示出来的头部地址栏和底部工具栏 如果现在有一个需求,用手机浏览器打开页面时,把地址栏和工具栏隐藏,该怎么办呢? 起初我在度娘找到了好几篇博客都 ...

  6. 【模态窗口-Modeldialog】提交请求时禁止在新窗口打开页面的处理方法

    在使用Window.ShowModalDialog()打开模态窗口后,在模态窗口内提交时总是会在新窗口中打开. 解决办法: 在要弹出的窗口的<head>之间加: <base targ ...

  7. 前端动态属性页面的 要用id做name 因为这样方便在提交表单时候取到值

    前端动态属性页面的 要用id做name 因为这样方便在提交表单时候取到值

  8. jquery模拟form表单提交并新打开页面

    /** * form表单提交本页面打开 * @param url * @param params */ function postCurrent(url,params){ var form = $(& ...

  9. 打开jsp页面时,显示空白页。

    打开jsp页面时,显示空白页.   #foreach($e in $listPlanItem)          #set($listPlanDetail=$!e.get(2))        < ...

随机推荐

  1. instanceof php

    instdnceof php5  的一个新成员 功能: 使用这个关键字可以确定一个对象是否是类的实例,是否是累的子类 ,还是实现了某个特定的接口. <?php class A{} class B ...

  2. 8.INSERT INTO 语句 UPDATE 语句

    1. INSERT INTO 语句 INSERT INTO 语句用于向表格中插入新的行. 语法 INSERT INTO 表名称 VALUES (值1, 值2,....) INSERT INTO Per ...

  3. p5156 [USACO18DEC]Sort It Out

    传送门 分析 我们发现对于没有发现的点相对位置不会发生改变 于是我们可以吧问题转化为求一个lis 于是我们字典序第k小的答案就是字典序第k大的lis 代码 #include<iostream&g ...

  4. Luogu 3237 [HNOI2014]米特运输

    BZOJ 3573 发现当一个点的权值确定了,整棵树的权值也会随之确定,这个确定关系表现在根结点的总权值上,如果一个点$x$的权值为$v$,那么一步步向上跳后,到根节点的权值就会变成$x*$每一个点的 ...

  5. Requests接口测试(三)

    一.定制请求头 我们先来看一下,关于请求头的定制演示,相信了解http协议的小伙伴应该对请求头部headers请求头部并不陌生,那么作为实际工作中的我们,如果想自定义一些请求头的信息,我们应该怎么办呢 ...

  6. oracle数据库之分组查询

    本章内容和大家分享的是数据当中的分组查询.分组查询复杂一点的是建立在多张表的查询的基础之上,(我们在上一节课的学习中已经给大家分享了多表查询的使用技巧,大家可以自行访问:多表查询1  多表查询2)而在 ...

  7. css总结11:css的overflow问题

    1 排版时经常遇到块级元素内容overflow,怎么妥当处理是一个关键. overflow的常用属性:  代码: <!DOCTYPE html><html lang="en ...

  8. sql2008调试存储过程

    拿上篇存储过程为例: 在意个窗口里面写上exec Proc_MoveUpOrDown2 'id',3,1,'tableName,'orderid' 按F11,有个黄色的箭头会指向该行, 再按F11会跳 ...

  9. Vim编码知识,乱码问题

    原文:http://demi-panda.com/2012/12/26/vim-encoding/ 在vim的初始学习阶段,乱码经常是困扰新手的一个比较烦躁的问题,本文试图阐述Vim的编码知识,及设置 ...

  10. 使用dom解析器对xml文档内容进行增删查改

    直接添代码: XML文档名称(one.xml) <?xml version="1.0" encoding="UTF-8" standalone=" ...