Beispiel #1
0
        public static string Submit(this HtmlAgilityPack.HtmlNode form, Encoding encoding)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            string postDataStr = form == null ? string.Empty :
                                 form.SelectNodes("//input").ToList()
                                 .ToDictionary(
                (input => input.GetAttributeValue("name", string.Empty)),
                (input => HttpUtility.UrlEncode(input.GetAttributeValue("value", string.Empty)))
                )
                                 .SerializeData <string>();

            byte[] responseData = HttpRequestUtil.Post(form?.GetAttributeValue("action", null),
                                                       encoding.GetBytes(postDataStr)
                                                       );

            return(encoding.GetString(responseData));
        }
Beispiel #2
0
        /// <summary>
        ///  获取网址HTML
        /// </summary>
        /// <param name="url">网址</param>
        /// <param name="encoding">编码</param>
        /// <returns> </returns>
        public static string GetHtmlContent(string url, Encoding encoding)
        {
            string html;

            using (StreamReader reader = HttpRequestUtil.GetHtmlContentStreamReader(url, encoding))
            {
                html = reader.ReadToEnd();
            }
            return(html);
        }
Beispiel #3
0
 public static StreamReader GetHtmlContentStreamReader(string url, Encoding encoding)
 {
     return(new StreamReader(HttpRequestUtil.GetHtmlContentStream(url), encoding));
 }