人民医院API

HttpHelperay.cs 26KB

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