-
大小: 182KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-05-18
- 语言: 其他
- 标签: Webrequest http request C#
资源简介
这是一个Webrequests模拟登录 ,获取网页源码,提取cookie,并提取验证码进行登录验证的示例,适合初学者
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Collections;
using System.Web;
namespace MyWebRequest
{
public partial class Form1 : Form
{
public CookieContainer cookieContainer;
protected static string cookieheader;
public Form1()
{
InitializeComponent();
loadData();
}
private void loadData()
{
cookieContainer = new CookieContainer();
string URI = “http://w9.s1.ab1999.net/login.php“;
// 设置打开页面的参数
HttpWebRequest request = WebRequest.Create(URI) as HttpWebRequest;
request.Method = “GET“;
request.KeepAlive = false;
request.CookieContainer = cookieContainer;
// 接收
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
cookieContainer.Add(response.Cookies);
response.Close();
URI = “http://w9.s1.ab1999.net/codeimg.php“;
DowloadCheckImg(URI cookieContainer);
}
///
/// 下载验证码图片并picturebox1显示
///
/// 验证码URL
/// Cookies值
public bool DowloadCheckImg(string Url CookieContainer cookCon)
{
bool bol = true;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Url);
//属性配置
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
webRequest.Accept = “image/gif image/x-xbitmap image/jpeg image/pjpeg application/x-shockwave-flash application/vnd.ms-excel application/vnd.ms-powerpoint application/msword */*“;
webRequest.UserAgent = “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)“;
// webRequest.ContentType = “application/x-www-form-urlencoded“;
webRequest.Method = “GET“;
// webRequest.Headers.Add(“Accept-Language“ “zh-cn“);
// webRequest.Headers.Add(“Accept-Encoding“ “gzipdeflate“);
webRequest.Referer = “http://w9.s1.ab1999.net/login.php“;
webRequest.KeepAlive = false;
webRequest.CookieContainer = cookieContainer;
try
{
//获取服务器返回的资源
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
// cookieContainer.Add(webResponse.Cookies);
using (Stream sream = webResponse.GetResponseStream())
{
pictureBox1.Image = System.Drawing.Image.FromStream(sream);
}
}
}
catch (WebException ex)
{
bol = false;
}
catch (Exception ex)
{
bol = false;
}
return bol;
}
//开始登录
private void btnNext_Click(object sender
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1128 2011-04-18 12:42 MyWebRequest\bin\Debug\image
文件 212992 2011-04-18 12:25 MyWebRequest\bin\Debug\Interop.MSxm
文件 139264 2011-04-18 22:50 MyWebRequest\bin\Debug\Interop.SHDocVw.dll
文件 32768 2011-04-19 09:29 MyWebRequest\bin\Debug\MyWebRequest.exe
文件 44544 2011-04-19 09:29 MyWebRequest\bin\Debug\MyWebRequest.pdb
文件 5632 2011-04-19 09:29 MyWebRequest\bin\Debug\MyWebRequest.vshost.exe
文件 12125 2011-04-19 00:06 MyWebRequest\Form1.cs
文件 9395 2011-04-18 23:12 MyWebRequest\Form1.Designer.cs
文件 5814 2011-04-18 23:12 MyWebRequest\Form1.resx
文件 4164 2011-04-19 09:28 MyWebRequest\FrmAfterLogin.cs
文件 5219 2011-04-19 00:58 MyWebRequest\FrmAfterLogin.Designer.cs
文件 5814 2011-04-19 00:58 MyWebRequest\FrmAfterLogin.resx
文件 4636 2011-04-18 23:12 MyWebRequest\MyWebRequest.csproj
文件 604 2011-04-17 23:43 MyWebRequest\MyWebRequest.csproj.user
文件 212992 2011-04-18 12:25 MyWebRequest\obj\Debug\Interop.MSxm
文件 139264 2011-04-18 22:50 MyWebRequest\obj\Debug\Interop.SHDocVw.dll
文件 973 2011-04-19 00:58 MyWebRequest\obj\Debug\MyWebRequest.csproj.GenerateResource.Cache
文件 542 2011-04-18 22:50 MyWebRequest\obj\Debug\MyWebRequest.csproj.ResolveComReference.cache
文件 32768 2011-04-19 09:29 MyWebRequest\obj\Debug\MyWebRequest.exe
文件 180 2011-04-18 23:12 MyWebRequest\obj\Debug\MyWebRequest.Form1.resources
文件 180 2011-04-19 00:58 MyWebRequest\obj\Debug\MyWebRequest.FrmAfterLogin.resources
文件 44544 2011-04-19 09:29 MyWebRequest\obj\Debug\MyWebRequest.pdb
文件 180 2011-04-18 23:12 MyWebRequest\obj\Debug\MyWebRequest.Properties.Resources.resources
文件 180 2011-04-18 23:12 MyWebRequest\obj\Debug\MyWebRequest.validateCode.resources
文件 1447 2011-04-19 09:29 MyWebRequest\obj\MyWebRequest.csproj.FileListAbsolute.txt
文件 471 2011-04-19 09:29 MyWebRequest\Program.cs
文件 1172 2011-04-17 22:36 MyWebRequest\Properties\AssemblyInfo.cs
文件 2880 2011-04-17 22:36 MyWebRequest\Properties\Resources.Designer.cs
文件 5350 2011-04-17 22:36 MyWebRequest\Properties\Resources.resx
文件 1097 2011-04-17 22:36 MyWebRequest\Properties\Settings.Designer.cs
............此处省略17个文件信息
- 上一篇:直流电机PWM调速系统的设计与仿真
- 下一篇:ZLG7289头文件
相关资源
- CustomHttpURLConnectionImpl
- HTTPS 数据传输
- HTTP服务器源代码
- httpclient请求httpsdemo
- NBU如何是磁带过期
- libghttp 1.0.9
- 最小的HTTP服务器
- .NET-OwinDog是一款支持OWIN标准的WEB应用
- Node.js-wechatcrawler一个微信文章抓取爬
- 易语言HTTPS代理服务器源码
- 从https://studiostyl.es的son-of-obsidian.vss
- httpsqs-1.7.tar.gz
- requests 安装包
- requests 实现的 api 自动化测试框架
- 微软https kb968730
- HttpClient工具类
- HttpHelper万能框架V2.1.10_DLL.rar
- pb9 通过http、https协议post
- https://download.csdn.net/download/p_xiaojia/9
- httpd基于端口的域名解析
- HttpClient工具详细
- ONENET笔记
- HTTP协议原理实践Web开发工程师必学
- nodejs实现带参微信公众号二维码进行
- https密钥和证书
- HttpHelper 万能框架V2.1.10
- httpClient 调用远程接口 获取数据到本
- HttpClient4.3教程.PDF
- 基于Qt的HTTP服务器
- [delphi]简单HTTP服务器架设源码
评论
共有 条评论