91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 30KB
    文件類型: .cs
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-08
  • 語(yǔ)言: C#
  • 標(biāo)簽: C#??winhttp??http??

資源簡(jiǎn)介

C# winhttp 開(kāi)發(fā)封裝類 簡(jiǎn)化get post 請(qǐng)求 帶cookie 可自定頭文件

資源截圖

代碼片段和文件信息

///?
///?類說(shuō)明:HttpHelper類,用來(lái)實(shí)現(xiàn)Http訪問(wèn),Post或者Get方式的,直接訪問(wèn),帶Cookie的,帶證書(shū)的等方式,可以設(shè)置代理
///?重要提示:請(qǐng)不要自行修改本類,如果因?yàn)槟阕约盒薷暮髮o(wú)法升級(jí)到新版本。如果確實(shí)有什么問(wèn)題請(qǐng)到官方網(wǎng)站提建議,
///?我們一定會(huì)及時(shí)修改
///?編碼日期:2011-09-20
///?編?碼?人:蘇飛
///?聯(lián)系方式:361983679??
///?官方網(wǎng)址:http://www.sufeinet.com/thread-3-1-1.html
///?修改日期:2017-09-30
///?版?本?號(hào):1.9
///?

using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Net;
using?System.IO;
using?System.Text.Regularexpressions;
using?System.IO.Compression;
using?System.Security.Cryptography.X509Certificates;
using?System.Net.Security;
using?System.Linq;
using?System.Net.Cache;

namespace?SufeiUtil
{
????///?
????///?Http連接操作幫助類
????///?

????public?class?HttpHelper
????{
????????#region?預(yù)定義方變量
????????//默認(rèn)的編碼
????????private?Encoding?encoding?=?Encoding.Default;
????????//Post數(shù)據(jù)編碼
????????private?Encoding?postencoding?=?Encoding.Default;
????????//HttpWebRequest對(duì)象用來(lái)發(fā)起請(qǐng)求
????????private?HttpWebRequest?request?=?null;
????????//獲取影響流的數(shù)據(jù)對(duì)象
????????private?HttpWebResponse?response?=?null;
????????//設(shè)置本地的出口ip和端口
????????private?IPEndPoint?_IPEndPoint?=?null;
????????#endregion

????????#region?Public

????????///?
????????///?根據(jù)相傳入的數(shù)據(jù),得到相應(yīng)頁(yè)面數(shù)據(jù)
????????///?

????????///?參數(shù)類對(duì)象
????????///?返回HttpResult類型
????????public?HttpResult?GetHtml(HttpItem?item)
????????{
????????????//返回參數(shù)
????????????HttpResult?result?=?new?HttpResult();
????????????try
????????????{
????????????????//準(zhǔn)備參數(shù)
????????????????SetRequest(item);
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????//配置參數(shù)時(shí)出錯(cuò)
????????????????return?new?HttpResult()?{?Cookie?=?string.Empty?Header?=?null?Html?=?ex.Message?StatusDescription?=?“配置參數(shù)時(shí)出錯(cuò):“?+?ex.Message?};
????????????}
????????????try
????????????{
????????????????//請(qǐng)求數(shù)據(jù)
????????????????using?(response?=?(HttpWebResponse)request.GetResponse())
????????????????{
????????????????????GetData(item?result);
????????????????}
????????????}
????????????catch?(WebException?ex)
????????????{
????????????????if?(ex.Response?!=?null)
????????????????{
????????????????????using?(response?=?(HttpWebResponse)ex.Response)
????????????????????{
????????????????????????GetData(item?result);
????????????????????}
????????????????}
????????????????else
????????????????{
????????????????????result.Html?=?ex.Message;
????????????????}
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????result.Html?=?ex.Message;
????????????}
????????????if?(item.IsToLower)?result.Html?=?result.Html.ToLower();
????????????//重置request,response為空
????????????if?(item.IsReset)
????????????{
????????????????request?=?null;
????????????????response?=?null;
????????????}
????????????return?result;
????????}
????????#endregion

????????#region?GetData

????????///?
????????///?獲取數(shù)據(jù)的并解析的方法
????????///?

????????

評(píng)論

共有 條評(píng)論