/// <summary>
/// WebClient的扩展
/// </summary>
public class webClient : WebClient
{
/// <summary>是否重定向 默认为true</summary>
public bool AllowAutoRedirect { get; set; }
/// <summary>
///获取或设置 Referer HTTP 标头的值。默认值为 null。
/// </summary>
public string Referer { get; set; }
/// <summary>
/// 获取或设置 Content-type HTTP 标头的值。 默认: application/x-www-form-urlencoded
/// </summary>
public string ContentType { get; set; }
/// <summary>
/// 获取或设置 User-agent HTTP 标头的值。默认:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
/// </summary>
public string UserAgent { get; set; } /// <summary>
/// 获取或设置 GetResponse 和 GetRequestStream 方法的超时值(以毫秒为单位)。 默认值是 30,000 毫秒(30 秒)。
/// </summary>
public int Timeout { get; set; }
/// <summary>
/// 获取或设置写入或读取流时的超时(以毫秒为单位)。默认值为 300,000 毫秒(5 分钟)
/// </summary>
public int ReadWriteTimeout { get; set; } /// <summary>获取或设置请求相关联的Cookie</summary>
public CookieContainer CookieContainer { get; set; }
/// <summary>创建一个新的 WebClient 实例。</summary>
public webClient()
{
this.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)";
this.ContentType = "application/x-www-form-urlencoded";
this.CookieContainer = new CookieContainer();
this.AllowAutoRedirect = true;
this.Timeout = * ;
this.ReadWriteTimeout = * ;
}
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
if (this.Referer != null) request.Referer = this.Referer;
if (this.ContentType != null) request.ContentType = this.ContentType;
if (this.UserAgent != null) request.UserAgent = this.UserAgent;
request.AllowAutoRedirect = this.AllowAutoRedirect;
request.CookieContainer = this.CookieContainer; //这句很关键,有了他可以保存返回的Cookie
request.Timeout = this.Timeout;
request.ReadWriteTimeout = this.ReadWriteTimeout;
return request;
}
}

带Cookie的 WebClient的更多相关文章

  1. postman发送带cookie的http请求

    1:需求:测试接口的访问权限,对于某些接口A可以访问,B不能访问. 2:问题:对于get请求很简单,登录之后,直接使用浏览器访问就可以: 对于post请求的怎么测试呢?前提是需要登录态,才能访问接口. ...

  2. HttpHelps类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式,可以设置代理

    原文地址:http://blog.csdn.net/cdefg198/article/details/8315438 万能框架:http://www.sufeinet.com/forum.php?mo ...

  3. 从WebBrowser中取得Cookie 和 WebClient设置cookie!

    原文:从WebBrowser中取得Cookie 和 WebClient设置cookie! 从WebBrowser中取得Cookie 的代码 CookieContainer myCookieContai ...

  4. HttpHelpers类普通GET和POST方式,带Cookie和带证书验证模式

    HttpHelpers类普通GET和POST方式,带Cookie和带证书验证模式 参考路径:https://www.cnblogs.com/splendidme/archive/2011/09/14/ ...

  5. postman 请求带cookie

    以亚马逊为例,我抓包随便看一个返回是json数据格式的一个接口,比如随便点一个,我的订单 随便找一条,然后复制url过滤 右键,copy下url 将url放入filter过滤: 在postman里面, ...

  6. QtQuick大坑笔记之Http的Get与Post操作(带cookie)

    前言 最近在为单位做一个简单的手机App,基于Qt技术栈的选择了QtQuick来开发.不得不说QtQucik开发的确舒服,很多东西都不用写就可以只用,UI定义起来也比较自由.但是本人想通过cookie ...

  7. urllib2 post请求方式,带cookie,添加请求头

    #encoding = utf-8 import urllib2import urllib url = 'http://httpbin.org/post'data={"name": ...

  8. PostMan 使用Interceptor 发送带cookie的请求一直loading

    问题 最近要写一个爬虫(虽然是第一次写),于是就用了Chrome上非常方便一个插件,PostMan,但是由于chrome安全的限制,发不出带cookie和带有自定义头部标签的请求. 百度一番后得如果想 ...

  9. asp.net web api 跨域,带cookie

    官网上有一个介绍 http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api 但是只支 ...

随机推荐

  1. 编写postgresql函数执行循环copy命令导入大数据

    CREATE OR REPLACE FUNCTION copyData() RETURNS boolean AS $BODY$ DECLARE i int; begin i :=1; FOR i IN ...

  2. postgresql全文检索语法

    第1章    全文检索语法 1.1 概述 查询引擎为文本数据类型提供~, ~*, LIKE和ILIKE操作符,并提供全文检索以识别自然语言文档,并通过相关性查询进行排序.查询引擎提供两种数据类型用于支 ...

  3. Iptables 规则 一些简单实例和详细介绍

    设定规则 iptables -p INPUT DROP iptables -p OUTPUT ACCEPT iptables -p FORWARD DROP 1.防止外网用内网IP欺骗 iptable ...

  4. web app 的技术参考 -- 来自 【百度移动建站指南】

    优化页面性能 考虑到移动设备和移动互联网的特点,在进行移动网站的页面开发设计时,一个总的原则是考虑用户访问的效率,降低页面加载时间.  下面的内容来自百度,然后我自己做了笔记.另外可参考这个系列的文章 ...

  5. MAC OSX使用公钥方式登录Linux服务器并进行安全加固

    登录Linux服务器的方式一般是使用ssh,直接使用密码登录既要记忆密码在输入过程中又有安全风险.所以本文将提供一个使用公钥登录的方式来解决输入密码的问题. 首先在mac上生成一个私钥.公钥对 首先, ...

  6. C#部分---类、异常保护;

    一:需要初始化的:随机数类.时间值类 随机数类:初始化 实例化//不允许将初始化的语句放置在循环中//Random ran = new Random(); 时间值类:/初始化 实例化//DateTim ...

  7. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  8. 什么是HTML、XML和XHTML

    (1)XMLXML是The Extensible Markup Language(可扩展标识语言)的简写.目前推荐遵循的是W3C于2000年10月6日发布的XML1.0,参考(www.w3.org/T ...

  9. Python爬虫学习笔记——豆瓣登陆(二)

    昨天能够登陆成功,但是不能使用cookies,今天试了一下requests库的Session(),发现可以保持会话了,代码只是稍作改动. #-*- coding:utf-8 -*- import re ...

  10. kuangbin_ShortPath H (POJ 3660)

    本来想自己写个bfs让他顺着胜负边爬 走到拐弯处就判定无法确定次序 然后我发现有多余的边并不会自己省略掉 要写个O(n^3)的删掉多余边这都不如Floyd了 看奚政学长写的是拓扑序也能解 然后在理解看 ...