Пример #1
0
        public HtmlAgilityPack.HtmlDocument PostRequest(String Url, System.Net.WebHeaderCollection Header, NameValueCollection formData)
        {
            try
                {
                    HttpClient httpClient = new HttpClient();
                    httpClient.SetTimeout(1800000);
                    byte[] responseBytes;
                    if (!ReferenceEquals(Header, null))
                    {
                        httpClient.Headers = Header;
                    }
                    if (!ReferenceEquals(formData, null))
                    {
                        httpClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                        responseBytes = httpClient.UploadValues(Url, "POST", formData);
                    }
                    else
                    {
                        responseBytes = httpClient.DownloadData(Url);
                    }
                    string resultAuthTicket = Encoding.UTF8.GetString(responseBytes);
                    httpClient.Dispose();
                    MemoryStream mStream = new MemoryStream(responseBytes);
                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                    document.Load(mStream);
                    return document;
                }
                catch (Exception ex)
                {

                        throw ex;
                }
        }
Пример #2
0
        public HtmlAgilityPack.HtmlDocument GetWebRequest(String Url)
        {
            try
            {
                HttpClient httpClient = new HttpClient();

                HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                byte[] responseBytes;
                responseBytes = httpClient.DownloadData(Url);
                MemoryStream mStream = new MemoryStream(responseBytes);
                document.Load(mStream);
                return document;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }