This repository was archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathHttpItems.cs
More file actions
451 lines (392 loc) · 10 KB
/
Copy pathHttpItems.cs
File metadata and controls
451 lines (392 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
using System;
using System.Net;
using System.Text;
namespace HttpCode.Core
{
/// <summary>
/// Http请求参考类
/// </summary>
[Serializable]
public class HttpItems
{
private string _accept =
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"
;
private bool _autoRedirectMax;
private string _cerPass;
private string _cerPath = string.Empty;
private CookieContainer _container;
private string _contentType = "application/x-www-form-urlencoded";
private string _cookie = string.Empty;
private string _encoding = string.Empty;
private string _method = "GET";
private string _postdata;
private byte[] _postdataByte;
private PostDataType _postDataType = PostDataType.String;
private Encoding _postEncoding = Encoding.Default;
private int _readWriteTimeout = 15000;
private string _referer = string.Empty;
private int _timeout = 15000;
private string _url;
private string _userAgent =
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.9 Safari/537.36";
private bool _useStringCookie = true;
private bool _allowautoredirect = true;
private int _connectionlimit = 1024;
private CookieCollection _cookiecollection;
/// <summary>
/// 默认的编码类型,如果不初始化,则为null,每次自动识别
/// </summary>
public Encoding Encoding = null;
/// <summary>
/// 当该属性设置为 true 时,使用 POST 方法的客户端请求应该从服务器收到 100-Continue 响应,以指示客户端应该发送要发送的数据。此机制使客户端能够在服务器根据请求报头打算拒绝请求时,避免在网络上发送大量的数据
/// </summary>
private bool _expect100Continue;
private WebHeaderCollection _header = new WebHeaderCollection();
private bool _isAjax;
private bool _isToLower;
private string _proxyip = string.Empty;
private string _proxypwd = string.Empty;
private string _proxyusername = string.Empty;
private ResultType _resulttype = ResultType.String;
/// <summary>
/// 请求URL必须填写
/// </summary>
public string Url
{
get => _url;
set => _url = value;
}
/// <summary>
/// 请求方式默认为GET方式
/// </summary>
public string Method
{
get => _method;
set => _method = value;
}
/// <summary>
/// 默认请求超时时间
/// </summary>
public int Timeout
{
get => _timeout;
set => _timeout = value;
}
/// <summary>
/// 默认写入Post数据超时间
/// </summary>
public int ReadWriteTimeout
{
get => _readWriteTimeout;
set => _readWriteTimeout = value;
}
/// <summary>
/// 请求标头值 默认为image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash,
/// application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
/// </summary>
public string Accept
{
get => _accept;
set => _accept = value;
}
/// <summary>
/// 请求返回类型默认 application/x-www-form-urlencoded
/// </summary>
public string ContentType
{
get => _contentType;
set => _contentType = value;
}
/// <summary>
/// 客户端访问信息默认Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.9
/// Safari/537.36
/// </summary>
public string UserAgent
{
get => _userAgent;
set => _userAgent = value;
}
/// <summary>
/// Post数据时的编码 默认为 Default,如需必要 请勿修改
/// </summary>
public Encoding PostEncoding
{
get => _postEncoding;
set => _postEncoding = value;
}
/// <summary>
/// 返回数据编码默认为NUll,可以自动识别
/// </summary>
public string EncodingStr
{
get => _encoding;
set => _encoding = value;
}
/// <summary>
/// Post的数据类型
/// </summary>
public PostDataType PostDataType
{
get => _postDataType;
set => _postDataType = value;
}
/// <summary>
/// Post请求时要发送的字符串Post数据
/// </summary>
public string Postdata
{
get => _postdata;
set => _postdata = value;
}
/// <summary>
/// Post请求时要发送的Byte类型的Post数据
/// </summary>
public byte[] PostdataByte
{
get => _postdataByte;
set => _postdataByte = value;
}
/// <summary>
/// Cookie对象集合
/// </summary>
public CookieCollection CookieCollection
{
get => _cookiecollection;
set => _cookiecollection = value;
}
/// <summary>
/// 自动处理cookie
/// </summary>
public CookieContainer Container
{
get => _container;
set => _container = value;
}
/// <summary>
/// 请求时的Cookie
/// </summary>
public string Cookie
{
get => _cookie;
set => _cookie = value;
}
/// <summary>
/// 来源地址,上次访问地址
/// </summary>
public string Referer
{
get => _referer;
set => _referer = value;
}
/// <summary>
/// 证书绝对路径
/// </summary>
public string CerPath
{
get => _cerPath;
set => _cerPath = value;
}
/// <summary>
/// 证书密码
/// </summary>
public string CerPass
{
get => _cerPass;
set => _cerPass = value;
}
/// <summary>
/// 是否设置为全文小写
/// </summary>
public bool IsToLower
{
get => _isToLower;
set => _isToLower = value;
}
/// <summary>
/// 是否增加异步请求头
/// 对应协议 : x-requested-with: XMLHttpRequest
/// </summary>
public bool IsAjax
{
get => _isAjax;
set => _isAjax = value;
}
/// <summary>
/// 支持跳转页面,查询结果将是跳转后的页面
/// </summary>
public bool Allowautoredirect
{
get => _allowautoredirect;
set => _allowautoredirect = value;
}
/// <summary>
/// 如果返回内容为 : 尝试自动重定向的次数太多 请设置本属性为true
/// 同时应注意设置超时时间(默认15s)
/// </summary>
public bool AutoRedirectMax
{
get => _autoRedirectMax;
set => _autoRedirectMax = value;
}
/// <summary>
/// 当该属性设置为 true 时,使用 POST 方法的客户端请求应该从服务器收到 100-Continue 响应,以指示客户端应该发送要发送的数据。此机制使客户端能够在服务器根据请求报头打算拒绝请求时,避免在网络上发送大量的数据
/// 默认False
/// </summary>
public bool Expect100Continue
{
get => _expect100Continue;
set => _expect100Continue = value;
}
/// <summary>
/// 最大连接数
/// </summary>
public int Connectionlimit
{
get => _connectionlimit;
set => _connectionlimit = value;
}
/// <summary>
/// 代理Proxy 服务器用户名
/// </summary>
public string ProxyUserName
{
get => _proxyusername;
set => _proxyusername = value;
}
/// <summary>
/// 代理 服务器密码
/// </summary>
public string ProxyPwd
{
get => _proxypwd;
set => _proxypwd = value;
}
/// <summary>
/// 代理 服务IP
/// </summary>
public string ProxyIp
{
get => _proxyip;
set => _proxyip = value;
}
/// <summary>
/// 设置返回类型String和Byte
/// </summary>
public ResultType ResultType
{
get => _resulttype;
set => _resulttype = value;
}
/// <summary>
/// 头数据
/// </summary>
public WebHeaderCollection Header
{
get => _header;
set => _header = value;
}
/// <summary>
/// 字符串头
/// </summary>
public string HeaderStr { get; set; }
/// <summary>
/// 如果提示以下错误,请设置为true
/// 服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF
/// </summary>
public bool UseUnsafe { get; set; }
/// <summary>
/// 如果提示以下错误,请设置为true
/// 从传输流收到意外的 EOF 或 0 个字节
/// </summary>
public bool IsEofError { get; set; }
/// <summary>
/// 是否为So模式
/// </summary>
public bool IsSo { get; set; }
/// <summary>
/// 文件上传路径
/// </summary>
public string UpLoadPath { get; set; }
/// <summary>
/// 是否请求图片
/// </summary>
public bool IsGetImage { get; set; }
/// <summary>
/// 是否使用字符串Cookie
/// </summary>
public bool UseStringCookie
{
get => _useStringCookie;
set => _useStringCookie = value;
}
/// <summary>
/// Https时的传输协议.
/// 替代原始SecurityProtocolType;
/// 包含四个版本(Ssl3 Tls Tls1.1 Tls1.2)
/// </summary>
public SecurityProtocolTypeEx SecProtocolTypeEx { get; set; }
/// <summary>
/// 是否设置SecurityProtocolType 默认为false
/// 如果需要设置具体属性,请使用SecProtocolTypeEx枚举
/// </summary>
public bool IsSetSecurityProtocolType { get; set; }
}
/// <summary>
/// Post的数据格式默认为string
/// </summary>
public enum PostDataType
{
/// <summary>
/// 字符串
/// </summary>
String, //字符串
/// <summary>
/// 字节流
/// </summary>
Byte, //字符串和字节流
/// <summary>
/// 文件路径
/// </summary>
FilePath //表示传入的是文件
}
/// <summary>
/// 返回类型
/// </summary>
public enum ResultType
{
/// <summary>
/// 表示只返回字符串
/// </summary>
String,
/// <summary>
/// 表示只返回字节流
/// </summary>
Byte,
/// <summary>
/// 急速请求,仅返回数据头
/// </summary>
So
}
/// <summary>
/// Https时的传输协议.
/// </summary>
public enum SecurityProtocolTypeEx
{
// 摘要:
// 指定安全套接字层 (SSL) 3.0 安全协议。
Ssl3 = 48,
//
// 摘要:
// 指定传输层安全 (TLS) 1.0 安全协议。
Tls = 192,
/// <summary>
/// 指定传输层安全 (TLS) 1.1 安全协议。
/// </summary>
Tls11 = 768,
/// <summary>
/// 指定传输层安全 (TLS) 1.2 安全协议。
/// </summary>
Tls12 = 3072
}
}