新野县12345_后端

HttpHelper.cs 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.IO;
  6. using System.Text.RegularExpressions;
  7. using System.IO.Compression;
  8. using System.Security.Cryptography.X509Certificates;
  9. using System.Net.Security;
  10. namespace CallCenter.Utility
  11. {
  12. /// <summary>
  13. /// Http连接操作帮助类
  14. /// </summary>
  15. public class HttpHelper
  16. {
  17. #region 预定义方法或者变更
  18. //默认的编码
  19. private Encoding encoding = Encoding.Default;
  20. //Post数据编码
  21. private Encoding postencoding = Encoding.Default;
  22. //HttpWebRequest对象用来发起请求
  23. private HttpWebRequest request = null;
  24. //获取影响流的数据对象
  25. private HttpWebResponse response = null;
  26. /// <summary>
  27. /// 根据相传入的数据,得到相应页面数据
  28. /// </summary>
  29. /// <param name="item">参数类对象</param>
  30. /// <returns>返回HttpResult类型</returns>
  31. public HttpResult GetHtml(HttpItem item)
  32. {
  33. //返回参数
  34. HttpResult result = new HttpResult();
  35. try
  36. {
  37. //准备参数
  38. SetRequest(item);
  39. }
  40. catch (Exception ex)
  41. {
  42. result = new HttpResult();
  43. result.Cookie = string.Empty;
  44. result.Header = null;
  45. result.Html = ex.Message;
  46. result.StatusDescription = "配置参数时出错:" + ex.Message;
  47. return result;
  48. }
  49. try
  50. {
  51. #region 得到请求的response
  52. using (response = (HttpWebResponse)request.GetResponse())
  53. {
  54. result.StatusCode = response.StatusCode;
  55. result.StatusDescription = response.StatusDescription;
  56. result.Header = response.Headers;
  57. if (response.Cookies != null) result.CookieCollection = response.Cookies;
  58. if (response.Headers["set-cookie"] != null) result.Cookie = response.Headers["set-cookie"];
  59. MemoryStream _stream = new MemoryStream();
  60. //GZIIP处理
  61. if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase))
  62. {
  63. //开始读取流并设置编码方式
  64. //new GZipStream(response.GetResponseStream(), CompressionMode.Decompress).CopyTo(_stream, 10240);
  65. //.net4.0以下写法
  66. _stream = GetMemoryStream(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress));
  67. }
  68. else
  69. {
  70. //开始读取流并设置编码方式
  71. //response.GetResponseStream().CopyTo(_stream, 10240);
  72. //.net4.0以下写法
  73. _stream = GetMemoryStream(response.GetResponseStream());
  74. }
  75. //获取Byte
  76. byte[] ResponseByte = _stream.ToArray();
  77. _stream.Close();
  78. if (ResponseByte != null & ResponseByte.Length > 0)
  79. {
  80. //是否返回Byte类型数据
  81. if (item.ResultType == ResultType.Byte) result.ResultByte = ResponseByte;
  82. //从这里开始我们要无视编码了
  83. if (encoding == null)
  84. {
  85. Match meta = Regex.Match(Encoding.Default.GetString(ResponseByte), "<meta([^<]*)charset=([^<]*)[\"']", RegexOptions.IgnoreCase);
  86. string c = (meta.Groups.Count > 1) ? meta.Groups[2].Value.ToLower().Trim() : string.Empty;
  87. if (c.Length > 2)
  88. {
  89. try
  90. {
  91. if (c.IndexOf(" ") > 0) c = c.Substring(0, c.IndexOf(" "));
  92. encoding = Encoding.GetEncoding(c.Replace("\"", "").Replace("'", "").Replace(";", "").Replace("iso-8859-1", "gbk").Trim());
  93. }
  94. catch
  95. {
  96. if (string.IsNullOrEmpty(response.CharacterSet)) encoding = Encoding.UTF8;
  97. else encoding = Encoding.GetEncoding(response.CharacterSet);
  98. }
  99. }
  100. else
  101. {
  102. if (string.IsNullOrEmpty(response.CharacterSet)) encoding = Encoding.UTF8;
  103. else encoding = Encoding.GetEncoding(response.CharacterSet);
  104. }
  105. }
  106. //得到返回的HTML
  107. result.Html = encoding.GetString(ResponseByte);
  108. }
  109. else
  110. {
  111. //得到返回的HTML
  112. result.Html = "";
  113. }
  114. }
  115. #endregion
  116. }
  117. catch (WebException ex)
  118. {
  119. //这里是在发生异常时返回的错误信息
  120. response = (HttpWebResponse)ex.Response;
  121. result.Html = ex.Message;
  122. if (response != null)
  123. {
  124. result.StatusCode = response.StatusCode;
  125. result.StatusDescription = response.StatusDescription;
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. result.Html = ex.Message;
  131. }
  132. if (item.IsToLower) result.Html = result.Html.ToLower();
  133. return result;
  134. }
  135. /// <summary>
  136. /// 4.0以下.net版本取数据使用
  137. /// </summary>
  138. /// <param name="streamResponse">流</param>
  139. private MemoryStream GetMemoryStream(Stream streamResponse)
  140. {
  141. MemoryStream _stream = new MemoryStream();
  142. int Length = 256;
  143. Byte[] buffer = new Byte[Length];
  144. int bytesRead = streamResponse.Read(buffer, 0, Length);
  145. while (bytesRead > 0)
  146. {
  147. _stream.Write(buffer, 0, bytesRead);
  148. bytesRead = streamResponse.Read(buffer, 0, Length);
  149. }
  150. return _stream;
  151. }
  152. /// <summary>
  153. /// 为请求准备参数
  154. /// </summary>
  155. ///<param name="item">参数列表</param>
  156. private void SetRequest(HttpItem item)
  157. {
  158. // 验证证书
  159. SetCer(item);
  160. //设置Header参数
  161. if (item.Header != null && item.Header.Count > 0) foreach (string key in item.Header.AllKeys)
  162. {
  163. request.Headers.Add(key, item.Header[key]);
  164. }
  165. // 设置代理
  166. SetProxy(item);
  167. if (item.ProtocolVersion != null) request.ProtocolVersion = item.ProtocolVersion;
  168. request.ServicePoint.Expect100Continue = item.Expect100Continue;
  169. //请求方式Get或者Post
  170. request.Method = item.Method;
  171. request.Timeout = item.Timeout;
  172. request.KeepAlive = item.KeepAlive;
  173. request.ReadWriteTimeout = item.ReadWriteTimeout;
  174. //Accept
  175. request.Accept = item.Accept;
  176. //ContentType返回类型
  177. request.ContentType = item.ContentType;
  178. //UserAgent客户端的访问类型,包括浏览器版本和操作系统信息
  179. request.UserAgent = item.UserAgent;
  180. // 编码
  181. encoding = item.Encoding;
  182. //设置Cookie
  183. SetCookie(item);
  184. //来源地址
  185. request.Referer = item.Referer;
  186. //是否执行跳转功能
  187. request.AllowAutoRedirect = item.Allowautoredirect;
  188. //设置Post数据
  189. SetPostData(item);
  190. //设置最大连接
  191. if (item.Connectionlimit > 0) request.ServicePoint.ConnectionLimit = item.Connectionlimit;
  192. }
  193. /// <summary>
  194. /// 设置证书
  195. /// </summary>
  196. /// <param name="item"></param>
  197. private void SetCer(HttpItem item)
  198. {
  199. if (!string.IsNullOrEmpty(item.CerPath))
  200. {
  201. //这一句一定要写在创建连接的前面。使用回调的方法进行证书验证。
  202. ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
  203. //初始化对像,并设置请求的URL地址
  204. request = (HttpWebRequest)WebRequest.Create(item.URL);
  205. SetCerList(item);
  206. //将证书添加到请求里
  207. request.ClientCertificates.Add(new X509Certificate(item.CerPath));
  208. }
  209. else
  210. {
  211. //初始化对像,并设置请求的URL地址
  212. request = (HttpWebRequest)WebRequest.Create(item.URL);
  213. SetCerList(item);
  214. }
  215. }
  216. /// <summary>
  217. /// 设置多个证书
  218. /// </summary>
  219. /// <param name="item"></param>
  220. private void SetCerList(HttpItem item)
  221. {
  222. if (item.ClentCertificates != null && item.ClentCertificates.Count > 0)
  223. {
  224. foreach (X509Certificate c in item.ClentCertificates)
  225. {
  226. request.ClientCertificates.Add(c);
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// 设置Cookie
  232. /// </summary>
  233. /// <param name="item">Http参数</param>
  234. private void SetCookie(HttpItem item)
  235. {
  236. //Cookie
  237. if (!string.IsNullOrEmpty(item.Cookie))
  238. {
  239. request.Headers[HttpRequestHeader.Cookie] = item.Cookie;
  240. }
  241. if (item.ResultCookieType == ResultCookieType.CookieCollection)
  242. {
  243. request.CookieContainer = new CookieContainer();
  244. }
  245. //设置CookieCollection
  246. if (item.CookieCollection != null && item.CookieCollection.Count > 0)
  247. {
  248. request.CookieContainer = new CookieContainer();
  249. request.CookieContainer.Add(item.CookieCollection);
  250. }
  251. }
  252. /// <summary>
  253. /// 设置Post数据
  254. /// </summary>
  255. /// <param name="item">Http参数</param>
  256. private void SetPostData(HttpItem item)
  257. {
  258. //验证在得到结果时是否有传入数据
  259. if (request.Method.Trim().ToLower().Contains("post"))
  260. {
  261. if (item.PostEncoding != null)
  262. {
  263. postencoding = item.PostEncoding;
  264. }
  265. byte[] buffer = null;
  266. //写入Byte类型
  267. if (item.PostDataType == PostDataType.Byte && item.PostdataByte != null && item.PostdataByte.Length > 0)
  268. {
  269. //验证在得到结果时是否有传入数据
  270. buffer = item.PostdataByte;
  271. }//写入文件
  272. else if (item.PostDataType == PostDataType.FilePath && !string.IsNullOrEmpty(item.Postdata))
  273. {
  274. StreamReader r = new StreamReader(item.Postdata, postencoding);
  275. buffer = postencoding.GetBytes(r.ReadToEnd());
  276. r.Close();
  277. } //写入字符串
  278. else if (!string.IsNullOrEmpty(item.Postdata))
  279. {
  280. buffer = postencoding.GetBytes(item.Postdata);
  281. }
  282. if (buffer != null)
  283. {
  284. request.ContentLength = buffer.Length;
  285. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  286. }
  287. }
  288. }
  289. /// <summary>
  290. /// 设置代理
  291. /// </summary>
  292. /// <param name="item">参数对象</param>
  293. private void SetProxy(HttpItem item)
  294. {
  295. if (!string.IsNullOrEmpty(item.ProxyIp))
  296. {
  297. //设置代理服务器
  298. if (item.ProxyIp.Contains(":"))
  299. {
  300. string[] plist = item.ProxyIp.Split(':');
  301. WebProxy myProxy = new WebProxy(plist[0].Trim(), Convert.ToInt32(plist[1].Trim()));
  302. //建议连接
  303. myProxy.Credentials = new NetworkCredential(item.ProxyUserName, item.ProxyPwd);
  304. //给当前请求对象
  305. request.Proxy = myProxy;
  306. }
  307. else
  308. {
  309. WebProxy myProxy = new WebProxy(item.ProxyIp, false);
  310. //建议连接
  311. myProxy.Credentials = new NetworkCredential(item.ProxyUserName, item.ProxyPwd);
  312. //给当前请求对象
  313. request.Proxy = myProxy;
  314. }
  315. //设置安全凭证
  316. request.Credentials = CredentialCache.DefaultCredentials;
  317. }
  318. else if (item.WebProxy != null)
  319. {
  320. request.Proxy = item.WebProxy;
  321. }
  322. }
  323. /// <summary>
  324. /// 回调验证证书问题
  325. /// </summary>
  326. /// <param name="sender">流对象</param>
  327. /// <param name="certificate">证书</param>
  328. /// <param name="chain">X509Chain</param>
  329. /// <param name="errors">SslPolicyErrors</param>
  330. /// <returns>bool</returns>
  331. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; }
  332. #endregion
  333. }
  334. /// <summary>
  335. /// Http请求参考类
  336. /// </summary>
  337. public class HttpItem
  338. {
  339. string _URL = string.Empty;
  340. /// <summary>
  341. /// 请求URL必须填写
  342. /// </summary>
  343. public string URL
  344. {
  345. get { return _URL; }
  346. set { _URL = value; }
  347. }
  348. string _Method = "GET";
  349. /// <summary>
  350. /// 请求方式默认为GET方式,当为POST方式时必须设置Postdata的值
  351. /// </summary>
  352. public string Method
  353. {
  354. get { return _Method; }
  355. set { _Method = value; }
  356. }
  357. int _Timeout = 100000;
  358. /// <summary>
  359. /// 默认请求超时时间
  360. /// </summary>
  361. public int Timeout
  362. {
  363. get { return _Timeout; }
  364. set { _Timeout = value; }
  365. }
  366. int _ReadWriteTimeout = 30000;
  367. /// <summary>
  368. /// 默认写入Post数据超时间
  369. /// </summary>
  370. public int ReadWriteTimeout
  371. {
  372. get { return _ReadWriteTimeout; }
  373. set { _ReadWriteTimeout = value; }
  374. }
  375. Boolean _KeepAlive = true;
  376. /// <summary>
  377. /// 获取或设置一个值,该值指示是否与 Internet 资源建立持久性连接默认为true。
  378. /// </summary>
  379. public Boolean KeepAlive
  380. {
  381. get { return _KeepAlive; }
  382. set { _KeepAlive = value; }
  383. }
  384. string _Accept = "text/html, application/xhtml+xml, */*";
  385. /// <summary>
  386. /// 请求标头值 默认为text/html, application/xhtml+xml, */*
  387. /// </summary>
  388. public string Accept
  389. {
  390. get { return _Accept; }
  391. set { _Accept = value; }
  392. }
  393. string _ContentType = "text/html";
  394. /// <summary>
  395. /// 请求返回类型默认 text/html
  396. /// </summary>
  397. public string ContentType
  398. {
  399. get { return _ContentType; }
  400. set { _ContentType = value; }
  401. }
  402. string _UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
  403. /// <summary>
  404. /// 客户端访问信息默认Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
  405. /// </summary>
  406. public string UserAgent
  407. {
  408. get { return _UserAgent; }
  409. set { _UserAgent = value; }
  410. }
  411. Encoding _Encoding = null;
  412. /// <summary>
  413. /// 返回数据编码默认为NUll,可以自动识别,一般为utf-8,gbk,gb2312
  414. /// </summary>
  415. public Encoding Encoding
  416. {
  417. get { return _Encoding; }
  418. set { _Encoding = value; }
  419. }
  420. private PostDataType _PostDataType = PostDataType.String;
  421. /// <summary>
  422. /// Post的数据类型
  423. /// </summary>
  424. public PostDataType PostDataType
  425. {
  426. get { return _PostDataType; }
  427. set { _PostDataType = value; }
  428. }
  429. string _Postdata = string.Empty;
  430. /// <summary>
  431. /// Post请求时要发送的字符串Post数据
  432. /// </summary>
  433. public string Postdata
  434. {
  435. get { return _Postdata; }
  436. set { _Postdata = value; }
  437. }
  438. private byte[] _PostdataByte = null;
  439. /// <summary>
  440. /// Post请求时要发送的Byte类型的Post数据
  441. /// </summary>
  442. public byte[] PostdataByte
  443. {
  444. get { return _PostdataByte; }
  445. set { _PostdataByte = value; }
  446. }
  447. private WebProxy _WebProxy;
  448. /// <summary>
  449. /// 设置代理对象
  450. /// </summary>
  451. public WebProxy WebProxy
  452. {
  453. get { return _WebProxy; }
  454. set { _WebProxy = value; }
  455. }
  456. CookieCollection cookiecollection = null;
  457. /// <summary>
  458. /// Cookie对象集合
  459. /// </summary>
  460. public CookieCollection CookieCollection
  461. {
  462. get { return cookiecollection; }
  463. set { cookiecollection = value; }
  464. }
  465. string _Cookie = string.Empty;
  466. /// <summary>
  467. /// 请求时的Cookie
  468. /// </summary>
  469. public string Cookie
  470. {
  471. get { return _Cookie; }
  472. set { _Cookie = value; }
  473. }
  474. string _Referer = string.Empty;
  475. /// <summary>
  476. /// 来源地址,上次访问地址
  477. /// </summary>
  478. public string Referer
  479. {
  480. get { return _Referer; }
  481. set { _Referer = value; }
  482. }
  483. string _CerPath = string.Empty;
  484. /// <summary>
  485. /// 证书绝对路径
  486. /// </summary>
  487. public string CerPath
  488. {
  489. get { return _CerPath; }
  490. set { _CerPath = value; }
  491. }
  492. private Boolean isToLower = false;
  493. /// <summary>
  494. /// 是否设置为全文小写,默认为不转化
  495. /// </summary>
  496. public Boolean IsToLower
  497. {
  498. get { return isToLower; }
  499. set { isToLower = value; }
  500. }
  501. private Boolean allowautoredirect = false;
  502. /// <summary>
  503. /// 支持跳转页面,查询结果将是跳转后的页面,默认是不跳转
  504. /// </summary>
  505. public Boolean Allowautoredirect
  506. {
  507. get { return allowautoredirect; }
  508. set { allowautoredirect = value; }
  509. }
  510. private int connectionlimit = 1024;
  511. /// <summary>
  512. /// 最大连接数
  513. /// </summary>
  514. public int Connectionlimit
  515. {
  516. get { return connectionlimit; }
  517. set { connectionlimit = value; }
  518. }
  519. private string proxyusername = string.Empty;
  520. /// <summary>
  521. /// 代理Proxy 服务器用户名
  522. /// </summary>
  523. public string ProxyUserName
  524. {
  525. get { return proxyusername; }
  526. set { proxyusername = value; }
  527. }
  528. private string proxypwd = string.Empty;
  529. /// <summary>
  530. /// 代理 服务器密码
  531. /// </summary>
  532. public string ProxyPwd
  533. {
  534. get { return proxypwd; }
  535. set { proxypwd = value; }
  536. }
  537. private string proxyip = string.Empty;
  538. /// <summary>
  539. /// 代理 服务IP
  540. /// </summary>
  541. public string ProxyIp
  542. {
  543. get { return proxyip; }
  544. set { proxyip = value; }
  545. }
  546. private ResultType resulttype = ResultType.String;
  547. /// <summary>
  548. /// 设置返回类型String和Byte
  549. /// </summary>
  550. public ResultType ResultType
  551. {
  552. get { return resulttype; }
  553. set { resulttype = value; }
  554. }
  555. private WebHeaderCollection header = new WebHeaderCollection();
  556. /// <summary>
  557. /// header对象
  558. /// </summary>
  559. public WebHeaderCollection Header
  560. {
  561. get { return header; }
  562. set { header = value; }
  563. }
  564. private Version _ProtocolVersion;
  565. /// <summary>
  566. // 获取或设置用于请求的 HTTP 版本。返回结果:用于请求的 HTTP 版本。默认为 System.Net.HttpVersion.Version11。
  567. /// </summary>
  568. public Version ProtocolVersion
  569. {
  570. get { return _ProtocolVersion; }
  571. set { _ProtocolVersion = value; }
  572. }
  573. private Boolean _expect100continue = true;
  574. /// <summary>
  575. /// 获取或设置一个 System.Boolean 值,该值确定是否使用 100-Continue 行为。如果 POST 请求需要 100-Continue 响应,则为 true;否则为 false。默认值为 true。
  576. /// </summary>
  577. public Boolean Expect100Continue
  578. {
  579. get { return _expect100continue; }
  580. set { _expect100continue = value; }
  581. }
  582. private X509CertificateCollection _ClentCertificates;
  583. /// <summary>
  584. /// 设置509证书集合
  585. /// </summary>
  586. public X509CertificateCollection ClentCertificates
  587. {
  588. get { return _ClentCertificates; }
  589. set { _ClentCertificates = value; }
  590. }
  591. private Encoding _PostEncoding;
  592. /// <summary>
  593. /// 设置或获取Post参数编码,默认的为Default编码
  594. /// </summary>
  595. public Encoding PostEncoding
  596. {
  597. get { return _PostEncoding; }
  598. set { _PostEncoding = value; }
  599. }
  600. private ResultCookieType _ResultCookieType = ResultCookieType.String;
  601. /// <summary>
  602. /// Cookie返回类型,默认的是只返回字符串类型
  603. /// </summary>
  604. public ResultCookieType ResultCookieType
  605. {
  606. get { return _ResultCookieType; }
  607. set { _ResultCookieType = value; }
  608. }
  609. }
  610. /// <summary>
  611. /// Http返回参数类
  612. /// </summary>
  613. public class HttpResult
  614. {
  615. private string _Cookie;
  616. /// <summary>
  617. /// Http请求返回的Cookie
  618. /// </summary>
  619. public string Cookie
  620. {
  621. get { return _Cookie; }
  622. set { _Cookie = value; }
  623. }
  624. private CookieCollection _CookieCollection;
  625. /// <summary>
  626. /// Cookie对象集合
  627. /// </summary>
  628. public CookieCollection CookieCollection
  629. {
  630. get { return _CookieCollection; }
  631. set { _CookieCollection = value; }
  632. }
  633. private string _Html;
  634. /// <summary>
  635. /// 返回的String类型数据 只有ResultType.String时才返回数据,其它情况为空
  636. /// </summary>
  637. public string Html
  638. {
  639. get { return _Html; }
  640. set { _Html = value; }
  641. }
  642. private byte[] _ResultByte;
  643. /// <summary>
  644. /// 返回的Byte数组 只有ResultType.Byte时才返回数据,其它情况为空
  645. /// </summary>
  646. public byte[] ResultByte
  647. {
  648. get { return _ResultByte; }
  649. set { _ResultByte = value; }
  650. }
  651. private WebHeaderCollection _Header;
  652. /// <summary>
  653. /// header对象
  654. /// </summary>
  655. public WebHeaderCollection Header
  656. {
  657. get { return _Header; }
  658. set { _Header = value; }
  659. }
  660. private string _StatusDescription;
  661. /// <summary>
  662. /// 返回状态说明
  663. /// </summary>
  664. public string StatusDescription
  665. {
  666. get { return _StatusDescription; }
  667. set { _StatusDescription = value; }
  668. }
  669. private HttpStatusCode _StatusCode;
  670. /// <summary>
  671. /// 返回状态码,默认为OK
  672. /// </summary>
  673. public HttpStatusCode StatusCode
  674. {
  675. get { return _StatusCode; }
  676. set { _StatusCode = value; }
  677. }
  678. }
  679. /// <summary>
  680. /// 返回类型
  681. /// </summary>
  682. public enum ResultType
  683. {
  684. /// <summary>
  685. /// 表示只返回字符串 只有Html有数据
  686. /// </summary>
  687. String,
  688. /// <summary>
  689. /// 表示返回字符串和字节流 ResultByte和Html都有数据返回
  690. /// </summary>
  691. Byte
  692. }
  693. /// <summary>
  694. /// Post的数据格式默认为string
  695. /// </summary>
  696. public enum PostDataType
  697. {
  698. /// <summary>
  699. /// 字符串类型,这时编码Encoding可不设置
  700. /// </summary>
  701. String,
  702. /// <summary>
  703. /// Byte类型,需要设置PostdataByte参数的值编码Encoding可设置为空
  704. /// </summary>
  705. Byte,
  706. /// <summary>
  707. /// 传文件,Postdata必须设置为文件的绝对路径,必须设置Encoding的值
  708. /// </summary>
  709. FilePath
  710. }
  711. /// <summary>
  712. /// Cookie返回类型
  713. /// </summary>
  714. public enum ResultCookieType
  715. {
  716. /// <summary>
  717. /// 只返回字符串类型的Cookie
  718. /// </summary>
  719. String,
  720. /// <summary>
  721. /// CookieCollection格式的Cookie集合同时也返回String类型的cookie
  722. /// </summary>
  723. CookieCollection
  724. }
  725. }