<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. string基本字符系列容器(二)

    string对象作为vector元素 string对象可以作为vector向量元素,这种用法类似字符串数组. #include<string> #include<vector> ...

  2. Docker学习笔记_Dockerfile常用指令

    Dockerfile常用指令

  3. 如何撤回经由Outlook2016刚发出的邮件

    在Outlook2016中,刚发出了一封邮件,发现有问题,想撤回,如何处理? 在对方尚未查看和接收时,可撤回. 参考步骤 1.选中这封邮件,用鼠标双击打开 2.点Move旁边的下拉按钮 3.点击&qu ...

  4. asp.net服务器推送长连接

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...

  5. Tomcat 与 数据库连接池 的小坑

    连接池的优点众所周知. 我们可以自己实现数据库连接池,也可引入实现数据库连接池的jar包,按要求进行配置后直接使用. 关于这方面的资料,好多dalao博客上记录的都是旧版本Tomcat的配置方式,很可 ...

  6. PS插件开发plugin

    Photoshop插件开发 VC++制作Photoshop自动化插件:http://blog.sina.com.cn/s/blog_73c52fda0101c7hw.html Photoshop 的扩 ...

  7. Eclipse下Android的NDK开发环境配置

    编辑2016年7月26日——增加了下载网址,修改了一些错误. 摸索了一周,走了很多弯路,磕磕绊绊,总算是弄好了NDK的开发环境,在这里总结一下吧. 一.Android NDK开发环境 首先下载安装JR ...

  8. 【Head First Java 读书笔记】(三)primitive主数据类型和引用

    认识变量 变量有两种:primitive数数据类型和引用. 声明变量 Java注重变量.它不会让你将浮点数类型变量放进整数类型的变量中,除非你先跟编译器确认过数字可以损失掉精确度. 为了要让类型安全能 ...

  9. JS Img对象获取图片高度宽度(兼容Chrome)

    一般获取图片高度宽度的写法: var img = new Image();img.src = imgsrc;var imgWH = CalcImgTiple(img.width, img.height ...

  10. PLSQL Developer连接远程Oracle

    注:内容来网络 (一)不安装客户端的解决办法. 第一种方法: 1.在安装ORACLE服务器的机器上搜索下列文件, oci.dll ocijdbc10.dll ociw32.dll orannzsbb1 ...