当前位置: 首页>>代码示例>>C#>>正文


C# HttpClient.Create方法代码示例

本文整理汇总了C#中HttpClient.Create方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.Create方法的具体用法?C# HttpClient.Create怎么用?C# HttpClient.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpClient的用法示例。


在下文中一共展示了HttpClient.Create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerificationIp

 /// <summary>
 /// 验证代理IP
 /// </summary>
 /// <returns></returns>
 public static bool VerificationIp(string ip, int port)
 {
     var client = new HttpClient();
     client.Setting.Proxy = new WebProxy(ip, port);
     var content = client.Create<string>(HttpMethod.Get, "https://www.baidu.com").Send();
     if (content.IsValid())
     {
         //Console.WriteLine(content.Result);
     }
     return content.IsValid();
 }
开发者ID:CBDlkl,项目名称:LiGather,代码行数:15,代码来源:ThreadValidate.cs

示例2: GetProxyByHttp

 /// <summary>
 /// 通过IP商获取代理IP
 /// </summary>
 /// <param name="nums">每次提取的IP数目</param>
 /// <returns></returns>
 private string GetProxyByHttp(int nums = 1)
 {
     var client = new HttpClient();
     while (true)
     {
         var content = client.Create<string>(HttpMethod.Get, "http://xvre.daili666api.com/ip/", data: new
         {
             tid = 557541152620047,
             num = nums,
             delay = 5,
             //category = 2,
             //sortby = "time",
             //foreign = "none",
             filter = "on"
         }).Send();
         if (content.IsValid())
         {
             return content.Result;
         }
         Thread.Sleep(1000 * 1); //一秒提取一次
     }
 }
开发者ID:CBDlkl,项目名称:LiGather,代码行数:27,代码来源:Proxy.cs

示例3: BaseWork

 /// <summary>
 /// 基单元
 /// </summary>
 private void BaseWork()
 {
     var httpclient = new HttpClient();
     while (TaskList.SurplusNum() > 0)
     {
         var company = TaskList.GetNextTask();
         QgOrgCodeEntity target = new QgOrgCodeEntity { companyName = company, TaskGuid = TaskEntity.Unique, InsertTime = DateTime.Now };
         //正文
         string data = "callCount=1\r\nc0-scriptName=ServiceForNum\r\nc0-methodName=getData\r\nc0-id=2025_1440664403388\r\nc0-e1=string:jgmc%20%3D" + company + "%20%20not%20ZYBZ%3D('2')%20\r\nc0-e2=string:jgmc%20%3D" + company + "%20%20not%20ZYBZ%3D('2')%20\r\nc0-e3=string:" + company + "\r\nc0-e4=string:2\r\nc0-e5=string:" + company + "\r\nc0-e6=string:%E5%85%A8%E5%9B%BD\r\nc0-e7=string:alll\r\nc0-e8=string:\r\nc0-e9=boolean:false\r\nc0-e10=boolean:true\r\nc0-e11=boolean:false\r\nc0-e12=boolean:false\r\nc0-e13=string:\r\nc0-e14=string:\r\nc0-e15=string:\r\nc0-param0=Object:{firststrfind:reference:c0-e1, strfind:reference:c0-e2, key:reference:c0-e3, kind:reference:c0-e4, tit1:reference:c0-e5, selecttags:reference:c0-e6, xzqhName:reference:c0-e7, button:reference:c0-e8, jgdm:reference:c0-e9, jgmc:reference:c0-e10, jgdz:reference:c0-e11, zch:reference:c0-e12, strJgmc:reference:c0-e13, :reference:c0-e14, secondSelectFlag:reference:c0-e15}\r\nxml=true";
         var context = httpclient.Create<string>(HttpMethod.Post, TargetUrl, data: data).Send();
         if (context.IsValid())
         {
             GetEntityList(context.Result, company, TaskEntity.Unique).ForEach(t =>
             {
                 new QgOrgCodeDomain().Add(t);
             });
         }
         else
         {
             new QgOrgCodeDomain().Add(target);
         }
     }
 }
开发者ID:CBDlkl,项目名称:LiGather,代码行数:26,代码来源:QgCrawler.cs

示例4: SingelSearch

        /// <summary>
        /// 单个查询
        /// </summary>
        /// <param name="companyName"></param>
        public void SingelSearch(string companyName)
        {
            var httpClient = new HttpClient();
            httpClient.Setting.Timeout = 1000 * 5;
            httpClient.Create<string>(HttpMethod.Post, firsturl).Send();
            while (true)
            {
                var targetModel = new CrawlerEntity { 搜索名称 = companyName, 操作人姓名 = TaskEntity.OperatorName, 入爬行库时间 = TaskEntity.CreateTime, TaskGuid = TaskEntity.Unique };
                try
                {
                    //IP处理
                    var proxyEntity = new ProxyDomain().GetByRandom(); //代理IP
                    if (proxyEntity == null)
                    {
                        Console.WriteLine("在线代理临时获取策略启动。");
                        proxyEntity = Proxy.Proxy.GetInstance().GetHttProxyEntity();
                        Console.WriteLine("线上获取到了代理:{0}:{1}", proxyEntity.IpAddress, proxyEntity.Port);
                    }

                    httpClient.Setting.Proxy = new WebProxy(proxyEntity.IpAddress, proxyEntity.Port);

                    var resultBody = httpClient.Create<string>(HttpMethod.Post, targetUrl, data: new
                    {
                        queryStr = targetModel.搜索名称,
                        module = "",
                        idFlag = "qyxy"
                    }).Send();
                    if (!resultBody.IsValid())
                    {
                        RemoveOldIp(proxyEntity);
                        continue;
                    }
                    if (ValidText(resultBody.Result))
                    {
                        RemoveOldIp(proxyEntity);
                        continue;
                    }
                    //提取二级连接
                    var parser = new JumonyParser();
                    var urls = parser.Parse(resultBody.Result).Find("li a").ToList();
                    var nextUrl = "";
                    if (urls.Count < 1)
                    {
                        AddNull(targetModel);
                        break;
                    }
                    foreach (var htmlElement in urls)
                    {
                        targetModel.名称 = htmlElement.InnerText();
                        nextUrl = url + htmlElement.Attribute("href").AttributeValue;
                    }
                    //提取目标正文
                    var resultsecondBody =
                        httpClient.Create<string>(HttpMethod.Get, zhuUrl + new Uri(firsturl + nextUrl).Query).Send();
                    var nameValueCollection =
                        new NameValueCollection(URL.GetQueryString(new Uri(firsturl + nextUrl).Query));
                    if (!resultsecondBody.IsValid())
                    {
                        RemoveOldIp(proxyEntity);
                        continue;
                    }
                    if (ValidText(resultsecondBody.Result))
                    {
                        RemoveOldIp(proxyEntity);
                        continue;
                    }
                    //正文处理
                    var sorceIhtml = new JumonyParser().Parse(resultsecondBody.Result.Replace("<th", "<td"));
                    var tableLists = sorceIhtml.Find("table[class='f-lbiao']").ToList();
                    var listall = new List<string>();
                    foreach (var tableList in tableLists)
                        tableList.Find("tr td")
                            .ForEach(t => listall.Add(t.InnerText().TrimEnd(':').TrimEnd(':').Trim()));
                    var fillModel = FillModel(listall);
                    fillModel.全局唯一编号 = nameValueCollection["reg_bus_ent_id"].ToUpper();
                    new CrawlerDomain().Add(StrategyNo1(fillModel, targetModel));
                    //后续其他处理 包括了IP使用状态,以查询列表状态
                    proxyEntity.Usage = proxyEntity.Usage + 1;
                    new ProxyDomain().Update(proxyEntity);
                    Console.WriteLine("{0} 抓取到:{1}", Task.CurrentId, targetModel.搜索名称);
                }
                catch (Exception e)
                {
                    new LogDomain().Add(new LogEntity { LogType = "error", TaskName = TaskEntity.TaskName, ErrorDetails = Task.CurrentId + "线程: " + e.Message, Details = e.ToString(), TriggerTime = DateTime.Now });
                    continue;
                }
                break;
            }
        }
开发者ID:CBDlkl,项目名称:LiGather,代码行数:93,代码来源:BjCrawler.cs

示例5: DownloadPage

 public static string DownloadPage(HttpMethod method, string url)
 {
     HttpClient client = new HttpClient();
     HttpContext<string> context = client.Create<string>(method, url);
     context.Send();
     return context.Result;
 }
开发者ID:wzymmy,项目名称:Unblock163MusicClient,代码行数:7,代码来源:Program.cs


注:本文中的HttpClient.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。