当前位置: 首页 > news >正文

政务公开网站开发江门专业网站建设公司

政务公开网站开发,江门专业网站建设公司,山西省建设工程信息网,网站备案手机号网页自动登录和提交POST信息的核心就是分析网页的源代码#xff08;HTML#xff09;#xff0c;在C#中#xff0c;可以用来提取网页HTML的组件比较多#xff0c;常用的用WebBrowser、WebClient、HttpWebRequest这三个。 以下就分别用这三种方法来实现#xff1a;1、WebBr…网页自动登录和提交POST信息的核心就是分析网页的源代码HTML在C#中可以用来提取网页HTML的组件比较多常用的用WebBrowser、WebClient、HttpWebRequest这三个。 以下就分别用这三种方法来实现1、WebBrowser是个迷你浏览器其特点是Post时不用关心Cookie、内置JS等问题WebBrowser是VS2005新提供的组件其实就是封装了IE接口实现POST功能一般在webBrowser的DocumentCompleted中分析HtmlDocument 来实现代码如下            HtmlElement ClickBtn null;           if (e.Url.ToString().ToLower().IndexOf(http://sandou.cnblogs.com/) 0)   //登陆页面            {                HtmlDocument doc webBrowser1.Document;                for (int i 0; i doc.All.Count ; i)                {                    if (doc.All[i].TagName.ToUpper().Equals(INPUT))                    {                        switch (doc.All[i].Name)                        {                            case userCtl:                                doc.All[i].InnerText user01;                                break;                            case passCt1:                                doc.All[i].InnerText mypass;                                break;                            case B1:                                ClickBtn doc.All[i]; //提交按钮                                break;                        }                    }                }                ClickBtn.InvokeMember(Click);   //执行按扭操作            } 2、WebClient封装了HTTP的一些类操作简单相较于webBrowser特点是可以自设代理缺点是对COOKIE的控制WebClient的运行全在后台并且提供了异步操作的能力这样很方便并发多个任务然后等待结果的返回再逐个处理。多任务异步调用的代码如下  private void StartLoop(int ProxyNum)        {           WebClient []  wcArray new WebClient[ProxyNum];  //初始化             for (int idArray 0; idArray ProxyNum;idArray)            {                 wcArray[idArray] new WebClient();                wcArray[idArray].OpenReadCompleted new OpenReadCompletedEventHandler(Pic_OpenReadCompleted2);                wcArray[idArray].UploadDataCompleted new UploadDataCompletedEventHandler(Pic_UploadDataCompleted2);                try                {                                        wcArray[idArray].Proxy new WebProxy(proxy[1], port);                    wcArray[idArray].OpenReadAsync(new Uri(http://sandou.cnblogs.com/)); //打开WEB;                    proxy null;                }                catch                {                }            }        }         private void Pic_OpenReadCompleted2(object sender, OpenReadCompletedEventArgs e)        {                if (e.Error null)                {                            string textData new StreamReader(e.Result, Encoding.Default).ReadToEnd();  //取返回信息                             ..                              String cookie ((WebClient)sender).ResponseHeaders[Set-Cookie];                             ((WebClient)sender).Headers.Add(Content-Type, application/x-www-form-urlencoded);                            ((WebClient)sender).Headers.Add(Accept-Language, zh-cn);                            ((WebClient)sender).Headers.Add(Cookie, cookie);                             string postData                             byte[] byteArray Encoding.UTF8.GetBytes(postData); // 转化成二进制数组                            ((WebClient)sender).UploadDataAsync(new Uri(http://sandou.cnblogs.com/), POST, byteArray);                }         }         private void Pic_UploadDataCompleted2(object sender, UploadDataCompletedEventArgs e)        {                 if (e.Error null)                {                    string returnMessage Encoding.Default.GetString(e.Result);                                    }       }   3、HttpWebRequest较为低层能实现的功能较多Cookie操作也很简单:         private bool  PostWebRequest()                {                   CookieContainer cc new CookieContainer();                    string pos tData user strUser pass strPsd;                    byte[] byteArray Encoding.UTF8.GetBytes(postData); // 转化                     HttpWebRequest webRequest2 (HttpWebRequest)WebRequest.Create(new Uri(http://sandou.cnblogs.com/));                    webRequest2.CookieContainer cc;                    webRequest2.Method POST;                    webRequest2.ContentType application/x-www-form-urlencoded;                    webRequest2.ContentLength byteArray.Length;                    Stream newStream webRequest2.GetRequestStream();                    // Send the data.                    newStream.Write(byteArray, 0, byteArray.Length);    //写入参数                    newStream.Close();                     HttpWebResponse response2 (HttpWebResponse)webRequest2.GetResponse();                    StreamReader sr2new StreamReader(response2.GetResponseStream(), Encoding.Default);                    string text2   sr2.ReadToEnd();                          }     HttpWebRequest 实现 这个是从网上COPY 的我以前用相关的代码登录到WWW.ASP.NET上并且成功post可惜代码不知道放什么地方了。 HttpWebRequest自动登录网站并获取网站内容不包含验证码的网站 可以使用 Visual Sniffer百度搜索 来捕捉提交的数据信息1. 访问你需要站外提交的页面比如 CSDN 登陆页 http://www.csdn.net/member/UserLogin.aspx2. 填写好需要的资料比如用户名和密码3. 打开 Visual Sniffer, 点“开始拦截”4. 在访问的页面中提交。5. 等提交成功之后在 Visual Sniffer 中“停止拦截”6. 在 Visual Sniffer 的左侧栏的加号中依次点开右边是它拦截到的内容  POST http://www.csdn.net/member/UserLogin.aspx HTTP/1.0Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*Referer: http://www.csdn.net/member/UserLogin.aspxAccept-Language: zh-cnContent-Type: application/x-www-form-urlencodedUA-CPU: x86Pragma: no-cacheUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; InfoPath.1)Host: www.csdn.netContent-Length: 355Proxy-Connection: Keep-AliveCookie: ASPSESSIONIDAAAATBQCFMEGGCKDBKHAMMCGKPFDMBFG; ASP.NET_SessionIdlusprmnom05lr445tmteaf55; userid699879 __EVENTTARGET__EVENTARGUMENT__VIEWSTATEdDwtMTcwMzgxNjQ2Mjs7bDxDU0ROVXNlckxvZ2luOmNiX1NhdmVTdGF0ZTtDU0ROVXNlckxvZ2luOkltYWdlX0xvZ2luOz4%2Btu1q2wmRZoAJTi9L73w1zBleylY%3DCSDNUserLogin%3Atb_UserNametestusernameCSDNUserLogin%3Atb_PasswordtestpasswordCSDNUserLogin%3Atb_ExPwd9232fromCSDNUserLogin%3AImage_Login.x36CSDNUserLogin%3AImage_Login.y6GET http://www.csdn.net/mycustompage.htm?aspxerrorpath/member/UserLogin.aspx HTTP/1.0Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*Referer: http://www.csdn.net/member/UserLogin.aspxAccept-Language: zh-cnUA-CPU: x86Pragma: no-cacheUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; InfoPath.1)Host: www.csdn.netProxy-Connection: Keep-AliveCookie: ASPSESSIONIDAAAATBQCFMEGGCKDBKHAMMCGKPFDMBFG; ASP.NET_SessionIdlusprmnom05lr445tmteaf55; userid699879以上为拦截内容其中提交数据的参数部分程序中的strArgs如__EVENTTARGET__EVENTARGUMENT__VIEWSTATEdDwtMTcwMzgxNjQ2Mjs7bDxDU0ROVXNlckxvZ2luOmNiX1NhdmVTdGF0ZTtDU0ROVXNlckxvZ2luOkltYWdlX0xvZ2luOz4%2Btu1q2wmRZoAJTi9L73w1zBleylY%3DCSDNUserLogin%3Atb_UserNametestusernameCSDNUserLogin%3Atb_PasswordtestpasswordCSDNUserLogin%3Atb_ExPwd9232          protected static string cookieHeader;        private void Page_Load(object sender, System.EventArgs e)        {            string strReContent string.Empty;            //登录            strReContent PostLogin(http://www.mystand.com.cn/login/submit.jsp提交的页面,提交的参数useridhgj0000password06045369,引用地址http://www.mystand.com.cn/);            //asp.net登录传递的参数需注意                //strReContent PostLogin(http://www.mystand.com.cn/login.aspx,__VIEWSTATEdDwtNjkzMjUyNDczO3Q8O2w8aTwzPjs%2BO2w8dDxwPHA8bDxUZXh0Oz47bDxcZTs%2BPjs%2BOzs%2BOz4%2BOz6aX2dtqkJTK%2BKbNPsjd7Op%2Fl26Iw%3D%3DtxtUserNamehxftxtPasswordhxf0000btnEnter%E7%99%BB%E5%BD%95,http://www.mystand.com.cn/login.aspx);            //获取页面            strReContent GetPage(http://www.mystand.com.cn/company/getdata.jsp?code,引用地址http://www.mystand.com.cn/);            //strReContent GetPage(http://www.mystand.com.cn/Modules/index.aspx,http://www.mystand.com.cn/login.aspx);            //可以对获得的内容进行处理strReContent        }         /** summary        /// 功能描述模拟登录页面提交登录数据进行登录并记录Header中的cookie        /// /summary        /// param namestrURL登录数据提交的页面地址/param        /// param namestrArgs用户登录数据/param        /// param namestrReferer引用地址/param        /// returns可以返回页面内容或不返回/returns        public static string PostLogin(string strURL,string strArgs,string strReferer)        {            string strResult ;            HttpWebRequest myHttpWebRequest (HttpWebRequest)WebRequest.Create(strURL);            myHttpWebRequest.AllowAutoRedirect true;             myHttpWebRequest.KeepAlive true;            myHttpWebRequest.Accept image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*;            myHttpWebRequest.Referer strReferer;                        myHttpWebRequest.UserAgent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727);            myHttpWebRequest.ContentType application/x-www-form-urlencoded;            myHttpWebRequest.Method POST;             CookieCollection myCookies null;            CookieContainer myCookieContainer new CookieContainer();            myHttpWebRequest.CookieContainer myCookieContainer;             Stream MyRequestStrearm myHttpWebRequest.GetRequestStream();            StreamWriter MyStreamWriter new StreamWriter(MyRequestStrearm,Encoding.ASCII);            //把数据写入HttpWebRequest的Request流            MyStreamWriter.Write(strArgs);            //关闭打开对象             MyStreamWriter.Close();            MyRequestStrearm.Close();             HttpWebResponse response null;            System.IO.StreamReader sr null;            response (HttpWebResponse)myHttpWebRequest.GetResponse();             cookieHeader myHttpWebRequest.CookieContainer.GetCookieHeader(new Uri(strURL));             HttpContext.Current.Application.Lock();             HttpContext.Current.Application[cookieHeader] cookieHeader;             HttpContext.Current.Application.UnLock();            myCookies response.Cookies;             sr new System.IO.StreamReader(response.GetResponseStream(),Encoding.GetEncoding(gb2312));    //    //utf-8            strResult sr.ReadToEnd();            return strResult;        }         /** summary        /// 功能描述在PostLogin成功登录后记录下Headers中的cookie然后获取此网站上其他页面的内容        /// /summary        /// param namestrURL获取网站的某页面的地址/param        /// param namestrReferer引用的地址/param        /// returns返回页面内容/returns        public static string GetPage(string strURL,string strReferer)        {            string strResult ;            HttpWebRequest myHttpWebRequest (HttpWebRequest)WebRequest.Create(strURL);            myHttpWebRequest.ContentType text/html;            myHttpWebRequest.Method GET;            myHttpWebRequest.Referer strReferer;            myHttpWebRequest.Headers.Add(cookie: cookieHeader);             HttpWebResponse response null;            System.IO.StreamReader sr null;            response (HttpWebResponse)myHttpWebRequest.GetResponse();            sr new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding(gb2312));    //    //utf-8            strResult sr.ReadToEnd();            return strResult;        } 技术应用——网页自动登录提交Post内容的用途很多如验证身份、程序升级、网络投票等以下是用C#实现的方法. 未解决问题——目前最大问题无法绕过验证码——我曾经和同事讨论图片的算法基本上很难识别网上也有很多识别验证码的例子但是对于简单的噪声还是可以的可是对于复杂的就一点用都没有了到目前为止我没有测试成功过如果你有测试成功过请帖代码我们一起研究研究。转载于:https://www.cnblogs.com/gxy217/archive/2012/06/07/2539121.html
http://wiki.neutronadmin.com/news/76451/

相关文章:

  • 郑州市惠济区建设局网站广州建模培训
  • 网站建设公司在哪里中企动力销售赚得多吗
  • 做京东网站需要哪些手续余姚哪里有做淘宝网站的
  • 行业网站解决方案智能建站
  • 我要自学网做网站wordpress自动上传外链图片
  • 做一个网站的计划书商业网站怎么做
  • 为学校网站做网站推广策划wordpress高端
  • 云南 网站模版电子商务+网站建设
  • 网站流量怎么做的wordpress 导航 class
  • 建筑公司做网站的好处网站建设趋势
  • 手机网站网址申请长沙域名注册
  • 住房城乡建设网站官网入口ppt模板免费下载免费
  • 南宁网站改版长沙seo公司排名
  • 备案网站公共查询家用电脑怎么做网站服务器
  • 企业建站业务还能做吗深圳模具外贸网站建设
  • 帮做ppt的网站做微信网站公司哪家好
  • 哪些网站可以免费做推广呢大连网站建设价格低
  • 没有网站做cpa泉州网站开发企业
  • 网站定制开发注意事项网页手机小游戏
  • 保安公司网站如何做商务卫士包括网站建设
  • 建设大型门户网站做百科权威网站有哪些
  • 公司网站可以做服务器吗注册网站那里能注册
  • 网站制作推广名片型网站开发
  • 建设网站用什么技术多种专业网站建设
  • wordpress_子网站重命名自建网站定位
  • 做网站都需要买什么wordpress静态优化
  • 网站租金可以做办公费吗电脑网站转手机版
  • 怎么做网站的登录界面做金融平台网站需要多少钱
  • 网站开发项目经验用ps做网站设计
  • 商城网站建设专业公司网站开发建议