C# HttpWebRequest获取COOKIES

  1. byte[] bytes = Encoding.Default.GetBytes(_post);
  2. CookieContainer myCookieContainer = new CookieContainer();
  3. try
  4. {
  5. //新建一个CookieContainer
  6. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(_loginurl);
  7. //新建一个HttpWebRequest
  8. myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
  9. myHttpWebRequest.AllowAutoRedirect = false;
  10. myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
  11. myHttpWebRequest.Timeout = ;
  12. myHttpWebRequest.KeepAlive = true;
  13. myHttpWebRequest.ContentLength = bytes.Length;
  14. myHttpWebRequest.Method = "POST";
  15. myHttpWebRequest.CookieContainer = myCookieContainer;
  16. //设置HttpWebRequest
  17. Stream myRequestStream = myHttpWebRequest.GetRequestStream();
  18. myRequestStream.Write(bytes, , bytes.Length);
  19. myRequestStream.Close();
  20. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
  21. foreach (Cookie ck in myHttpWebResponse.Cookies)
  22. {
  23. myCookieContainer.Add(ck);
  24. }
  25. myHttpWebResponse.Close();
  26. }
  27. catch
  28. {
  29. MessageBox.show("获取COOKIES失败!");
  30. return;
  31. }

C# HttpWebRequest获取COOKIES的更多相关文章

  1. HttpWebRequest 保存Cookies,模拟Session登录

    前面使用HttpWebRequest 对象可以抓取网页中一些资料,不过有些页面可以直接打开,而有些页面必登录之后才能打开,也就是在登录后保存登录信息在Session,这样就可以访问有权限的页面了.下面 ...

  2. c#利用HttpWebRequest获取网页源代码

    c#利用HttpWebRequest获取网页源代码,搞了好几天终于解决了,直接获取网站编码进行数据读取,再也不用担心乱码了! 命名空间:Using System.Net private static ...

  3. 用selenium获取cookies

    前言:由于登录反爬措施的越来越麻烦,甚至出现了12306这种看图识物的无敌验证码,我只能说,我选择死亡.这就衍生出了使用selenium来获取获取cookies. 实例:获取qq空间cookies,亲 ...

  4. httpWebRequest获取流和WebClient的文件抓取

    httpWebRequest获取流和WebClient的文件抓取 昨天写一个抓取,遇到了一个坑,就是在获取网络流的时候,人为的使用了stream.Length来获取流的长度,获取的时候会抛出错误,查了 ...

  5. 微博验证码的识别并登录获取cookies

    记得以前微博是用的宫格验证码,现在不一样了,用的是滑块验证码和 点触验证码,每天登陆的第一次基本用的是滑块,继续登录就都用的是点触验证码.所以滑块验证码不写,感兴趣的可以补上. 代码: 这里用的超级鹰 ...

  6. 【接口测试】使用httpClient获取cookies+携带获取的cookies访问get接口

    数据准备 在本机或者远端机器安装部署moco-runner(参考:https://blog.csdn.net/qq_32706349/article/details/80472445) 这里我们只需要 ...

  7. VC获取cookies的几种方法

    方法一: CInternetSession::GetCookie This member function implements the behavior of the Win32 function  ...

  8. (九)HttpClient获取cookies

    原文链接:https://blog.csdn.net/cheny1p1ng/article/details/90780024 旧版本DefaultHttpClient 使用getCookieStore ...

  9. requests请求获取cookies的字典格式

    python中requests请求的cookies值一般是jar包,如何将cookies值改为字典,此处运用了方法.举例如下: import  requests response = requests ...

随机推荐

  1. vsftpd 安装配置

    # vsftp 安装yum install vsftpd -y # 配置用户名密码时需要yum install db* db4* -y# 启动vsftpdservice vsftpd start # ...

  2. Linux下安装jdk1.7、Apache-tomcat7

    首先说明下我的主机环境:主机:32位win7 虚拟机:VMware Workstation10.0.1 linux:红帽子centos6.4 jdk1.7 Apache-tomcat7 java环境需 ...

  3. 免费上google的方法

    访问http://www.ishadowsocks.net/这上面有详细介绍

  4. HBase Zookeeper 安装学习

    https://my.oschina.net/hanzhankang/blog/129335 http://blog.itpub.net/27099995/viewspace-1394831/ htt ...

  5. hadoop fs -ls no such file or directory

    http://blog.csdn.net/baolibin528/article/details/43650919

  6. iOS 解决LaunchScreen中图片加载黑屏问题

    iOS 解决LaunchScreen中图片加载黑屏问题 原文: http://blog.csdn.net/chengkaizone/article/details/50478045 iOS 解决Lau ...

  7. SimpleDateFormat使用详解——日期、字符串应用

    public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方式格式化和分析数据的具体类. 它允许格式化 (d ...

  8. 解读ASP.NET 5 & MVC6系列(13):TagHelper

    在新版的MVC6中,微软提供了强大的TagHelper功能,以便让我们摆脱如下的臃肿代码: @Html.LabelFor(model => model.FullName) @Html.EditF ...

  9. CentOS7下安装并简单设置PostgreSQL笔记

    为什么是PostgreSQL? 在.NET Core诞生之前,微软平台上最常见的开发组件便是.NET Framework + SQL Server了,但是现在.NET Core终于让跨平台部署成为了现 ...

  10. [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...