C# HttpWebRequest获取COOKIES
C# HttpWebRequest获取COOKIES
- byte[] bytes = Encoding.Default.GetBytes(_post);
- CookieContainer myCookieContainer = new CookieContainer();
- try
- {
- //新建一个CookieContainer
- HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(_loginurl);
- //新建一个HttpWebRequest
- myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
- myHttpWebRequest.AllowAutoRedirect = false;
- myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
- myHttpWebRequest.Timeout = ;
- myHttpWebRequest.KeepAlive = true;
- myHttpWebRequest.ContentLength = bytes.Length;
- myHttpWebRequest.Method = "POST";
- myHttpWebRequest.CookieContainer = myCookieContainer;
- //设置HttpWebRequest
- Stream myRequestStream = myHttpWebRequest.GetRequestStream();
- myRequestStream.Write(bytes, , bytes.Length);
- myRequestStream.Close();
- HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
- foreach (Cookie ck in myHttpWebResponse.Cookies)
- {
- myCookieContainer.Add(ck);
- }
- myHttpWebResponse.Close();
- }
- catch
- {
- MessageBox.show("获取COOKIES失败!");
- return;
- }
C# HttpWebRequest获取COOKIES的更多相关文章
- HttpWebRequest 保存Cookies,模拟Session登录
前面使用HttpWebRequest 对象可以抓取网页中一些资料,不过有些页面可以直接打开,而有些页面必登录之后才能打开,也就是在登录后保存登录信息在Session,这样就可以访问有权限的页面了.下面 ...
- c#利用HttpWebRequest获取网页源代码
c#利用HttpWebRequest获取网页源代码,搞了好几天终于解决了,直接获取网站编码进行数据读取,再也不用担心乱码了! 命名空间:Using System.Net private static ...
- 用selenium获取cookies
前言:由于登录反爬措施的越来越麻烦,甚至出现了12306这种看图识物的无敌验证码,我只能说,我选择死亡.这就衍生出了使用selenium来获取获取cookies. 实例:获取qq空间cookies,亲 ...
- httpWebRequest获取流和WebClient的文件抓取
httpWebRequest获取流和WebClient的文件抓取 昨天写一个抓取,遇到了一个坑,就是在获取网络流的时候,人为的使用了stream.Length来获取流的长度,获取的时候会抛出错误,查了 ...
- 微博验证码的识别并登录获取cookies
记得以前微博是用的宫格验证码,现在不一样了,用的是滑块验证码和 点触验证码,每天登陆的第一次基本用的是滑块,继续登录就都用的是点触验证码.所以滑块验证码不写,感兴趣的可以补上. 代码: 这里用的超级鹰 ...
- 【接口测试】使用httpClient获取cookies+携带获取的cookies访问get接口
数据准备 在本机或者远端机器安装部署moco-runner(参考:https://blog.csdn.net/qq_32706349/article/details/80472445) 这里我们只需要 ...
- VC获取cookies的几种方法
方法一: CInternetSession::GetCookie This member function implements the behavior of the Win32 function ...
- (九)HttpClient获取cookies
原文链接:https://blog.csdn.net/cheny1p1ng/article/details/90780024 旧版本DefaultHttpClient 使用getCookieStore ...
- requests请求获取cookies的字典格式
python中requests请求的cookies值一般是jar包,如何将cookies值改为字典,此处运用了方法.举例如下: import requests response = requests ...
随机推荐
- vsftpd 安装配置
# vsftp 安装yum install vsftpd -y # 配置用户名密码时需要yum install db* db4* -y# 启动vsftpdservice vsftpd start # ...
- Linux下安装jdk1.7、Apache-tomcat7
首先说明下我的主机环境:主机:32位win7 虚拟机:VMware Workstation10.0.1 linux:红帽子centos6.4 jdk1.7 Apache-tomcat7 java环境需 ...
- 免费上google的方法
访问http://www.ishadowsocks.net/这上面有详细介绍
- HBase Zookeeper 安装学习
https://my.oschina.net/hanzhankang/blog/129335 http://blog.itpub.net/27099995/viewspace-1394831/ htt ...
- hadoop fs -ls no such file or directory
http://blog.csdn.net/baolibin528/article/details/43650919
- iOS 解决LaunchScreen中图片加载黑屏问题
iOS 解决LaunchScreen中图片加载黑屏问题 原文: http://blog.csdn.net/chengkaizone/article/details/50478045 iOS 解决Lau ...
- SimpleDateFormat使用详解——日期、字符串应用
public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方式格式化和分析数据的具体类. 它允许格式化 (d ...
- 解读ASP.NET 5 & MVC6系列(13):TagHelper
在新版的MVC6中,微软提供了强大的TagHelper功能,以便让我们摆脱如下的臃肿代码: @Html.LabelFor(model => model.FullName) @Html.EditF ...
- CentOS7下安装并简单设置PostgreSQL笔记
为什么是PostgreSQL? 在.NET Core诞生之前,微软平台上最常见的开发组件便是.NET Framework + SQL Server了,但是现在.NET Core终于让跨平台部署成为了现 ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...