带Cookie的 WebClient
/// <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的更多相关文章
- postman发送带cookie的http请求
1:需求:测试接口的访问权限,对于某些接口A可以访问,B不能访问. 2:问题:对于get请求很简单,登录之后,直接使用浏览器访问就可以: 对于post请求的怎么测试呢?前提是需要登录态,才能访问接口. ...
- HttpHelps类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式,可以设置代理
原文地址:http://blog.csdn.net/cdefg198/article/details/8315438 万能框架:http://www.sufeinet.com/forum.php?mo ...
- 从WebBrowser中取得Cookie 和 WebClient设置cookie!
原文:从WebBrowser中取得Cookie 和 WebClient设置cookie! 从WebBrowser中取得Cookie 的代码 CookieContainer myCookieContai ...
- HttpHelpers类普通GET和POST方式,带Cookie和带证书验证模式
HttpHelpers类普通GET和POST方式,带Cookie和带证书验证模式 参考路径:https://www.cnblogs.com/splendidme/archive/2011/09/14/ ...
- postman 请求带cookie
以亚马逊为例,我抓包随便看一个返回是json数据格式的一个接口,比如随便点一个,我的订单 随便找一条,然后复制url过滤 右键,copy下url 将url放入filter过滤: 在postman里面, ...
- QtQuick大坑笔记之Http的Get与Post操作(带cookie)
前言 最近在为单位做一个简单的手机App,基于Qt技术栈的选择了QtQuick来开发.不得不说QtQucik开发的确舒服,很多东西都不用写就可以只用,UI定义起来也比较自由.但是本人想通过cookie ...
- urllib2 post请求方式,带cookie,添加请求头
#encoding = utf-8 import urllib2import urllib url = 'http://httpbin.org/post'data={"name": ...
- PostMan 使用Interceptor 发送带cookie的请求一直loading
问题 最近要写一个爬虫(虽然是第一次写),于是就用了Chrome上非常方便一个插件,PostMan,但是由于chrome安全的限制,发不出带cookie和带有自定义头部标签的请求. 百度一番后得如果想 ...
- asp.net web api 跨域,带cookie
官网上有一个介绍 http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api 但是只支 ...
随机推荐
- 第一个demo
1.首先这是最初的概念模型. 2.最后设计成这样. 3.运行
- 使用SCP在命令行传输文件
下载远程服务器上的文件 scp root@10.0.10.10:/home/user/download.txt ./download.txt 上传文件到远程服务器 scp ./upload.t ...
- The Implementation of Lua 5.0 阅读笔记(一)
没想到Lua的作者理论水平这么高,这篇文章读的我顿生高屋建瓴之感.云风分享了一篇中译:http://www.codingnow.com/2000/download/The%20Implementati ...
- 137. Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- ZOJ 1048 Financial Management
原题链接 题目大意:给出12个月的收入,求一个平均值. 解法:没什么好说的,就是一个除法. 参考代码: #include<stdio.h> int main(){ int i; float ...
- Angular 通过 $http.post 写入本地 JSON 文件
最近在练习使用 Angular,在实现 $http 对本地 JSON 文档读写的时候遇到了问题. 问题 使用 GET 方法成功将 JSON 文档的内容读出来:但是在使用 POST 插入本地 JSON ...
- Jpush教材
http://docs.jpush.cn/pages/viewpage.action?pageId=3309574
- 【NOIP2010】关押罪犯
一开始看错题了,然后怎么想都想不明白--原题: S 城现有两座监狱,一共关押着 N 名罪犯,编号分别为 1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲 ...
- java编程之:org.apache.commons.lang3.text.StrTokenizer
第一个api测试:按特殊符号进行分词,并遍历每一个分词部分 public static void main(String[] args) { String aString="AB-CD-EF ...
- 最简puremvc
工程如下,看来sendNotification是像comand和mediator发消息的 package { import flash.display.Sprite; import flash.eve ...