Http post 接收 html .netcore

/// <summary>
        /// 获取主证信息
        /// </summary>
        /// <param name="getDatas"></param>
        public void MainSyndrome(List<ProductionAndOperationLicenseEntity> getDatas)
        {

            //获取品种审定信息
            using (var db = DbFactory.DefaultDbContext())
            {

                string baseUrl = config.MainSyndromeUrl + "SeedSearch/SeedSolution/Business/.ashx?Type=SLImpLicence&LicenceID={0}";

                MainSyndromeRequest mainSyndromeReq = new MainSyndromeRequest();
                POMainSyndromeEntity pOMainSyndrome = new POMainSyndromeEntity();
                foreach (ProductionAndOperationLicenseEntity item in getDatas)
                {
                    //用的postMan的方法
                    var client = new RestClient(string.Format(baseUrl, item.LicenceID));
                    client.Timeout = -1;
                    var request = new RestRequest(Method.POST);
                    IRestResponse response = client.Execute(request);
                    
                    //请求是否成功
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        mainSyndromeReq = JsonConvert.DeserializeObject<MainSyndromeRequest>(response.Content);
                        if (mainSyndromeReq.Success)
                        {
                            MainSyndromeCharacterProcessing(mainSyndromeReq.ResultData);
                        }
                        //pOMainSyndromes.AddRange(response.Value.rows.ToString().ToEntity<List<SeedExportEntity>>());
                    }

                }
                
            }

        }

        public POMainSyndromeEntity MainSyndromeCharacterProcessing(string resultDataStr)
        {
            //字符替换
            resultDataStr = resultDataStr.Replace("\r","");
            resultDataStr = resultDataStr.Replace("\n","");
            resultDataStr = resultDataStr.Replace(" ","");
            resultDataStr = ReplaceHtmlTag(resultDataStr,"&");
            
            
            string[] resultStr = resultDataStr.Split('&');
            
            Dictionary<int, string> dic = new Dictionary<int, string>();
            int i = 0;
            foreach (var item in resultStr)
            {
                dic.Add(i, item);
                i++;
            }

            POMainSyndromeEntity pOMainSyndrome = new POMainSyndromeEntity();
            pOMainSyndrome.Residence = dic[18];
            pOMainSyndrome.LegalRepresentative = dic[2];
            pOMainSyndrome.ProductionAndManagementParadigm = dic[21];
            pOMainSyndrome.EffectiveArea = dic[21];
            pOMainSyndrome.UnifiedSocialCreditCode = dic[24];
            pOMainSyndrome.IssuingSuthority = dic[3];
            return pOMainSyndrome;
            
        }

        public static string ReplaceHtmlTag(string html,string intervalStr, int length = 0)
        {
            string strText = System.Text.RegularExpressions.Regex.Replace(html, "</[^>]+>", "!");
            strText = System.Text.RegularExpressions.Regex.Replace(strText, "<[^>]+>", "#");
            strText = System.Text.RegularExpressions.Regex.Replace(strText, "&[^;]+;", "");
            strText = System.Text.RegularExpressions.Regex.Replace(strText, "!#", intervalStr);
            strText = System.Text.RegularExpressions.Regex.Replace(strText, "#", "");
            strText = System.Text.RegularExpressions.Regex.Replace(strText, "!", "");
            
            if (length > 0 && strText.Length > length)
                return strText.Substring(0, length);

            return strText;
        }
posted @ 2020-05-28 17:39  唯爱金生  阅读(439)  评论(0编辑  收藏  举报