using DotNet4.Utilities; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LiveTools { public class RyPostGet { /// /// 以post方式获取网页源码 /// /// /// /// /// public HttpResult Post(string url, string post, string cookie) { try { HttpHelper t = new HttpHelper(); HttpItem m = new HttpItem() { URL = url, Postdata = post, ContentType = "application/x-www-form-urlencoded", Method = "POST", Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", Expect100Continue = false }; if (cookie != "") { m.Cookie = cookie; } HttpResult r = t.GetHtml(m); return r; } catch { HttpResult r = new HttpResult(); return r; } } /// /// 以post方式获取网页源码 /// /// /// /// public HttpResult Post(string url, string post) { return Post(url, post, cookie); } /// /// 获取网页源码 /// /// /// /// public HttpResult Get(string url, string cookie) { try { HttpHelper t = new HttpHelper(); HttpItem m = new HttpItem() { URL = url }; if (cookie != "") { m.Cookie = cookie; } m.Allowautoredirect = true; HttpResult r = t.GetHtml(m); return r; } catch { HttpResult r = new HttpResult(); return r; } } /// /// 获取网页源码 /// /// /// public HttpResult Get(string url) { return Get(url, cookie); } public string Cookie { get { return cookie; } set { cookie = value; } } private string cookie = ""; public static string UrlEncode(string str) { StringBuilder sb = new StringBuilder(); byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str) for (int i = 0; i < byStr.Length; i++) { sb.Append(@"%" + Convert.ToString(byStr[i], 16)); } return (sb.ToString()); } public static string GetMD5(string str) { StringBuilder sb = new StringBuilder(); foreach (byte b in System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(str))) { sb.Append(b.ToString("X2")); } return sb.ToString().Trim(); } } }