public static string GetTickect(string acessToken) { HttpHelper helper = new HttpHelper(); string url = string.Format(@"https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", acessToken); string result = helper.Get(url, null); return result; }
protected void Page_Load(object sender, EventArgs e) { //创建Httphelper对象 HttpHelper http = new HttpHelper(); //创建Httphelper参数对象 HttpItem item = new HttpItem() { URL = "http://www.sufeinet.com",//URL 必需项 Method = "get",//URL 可选项 默认为Get ContentType = "text/html",//返回类型 可选项有默认值 ResultCookieType = ResultCookieType.CookieCollection }; //请求的返回值对象 HttpResult result = http.GetHtml(item); //获取请求的Cookie CookieCollection cookie = result.CookieCollection; // 第二次使用Cookie //创建Httphelper参数对象 item = new HttpItem() { URL = "http://www.sufeinet.com/thread-9989-1-1.html",//URL 必需项 Method = "get",//URL 可选项 默认为Get ContentType = "text/html",//返回类型 可选项有默认值 CookieCollection = cookie,//把Cookie写入请求串中 ResultCookieType = ResultCookieType.CookieCollection }; //请求的返回值对象 result = http.GetHtml(item); //获取Html string html = result.Html; }
protected void Page_Load(object sender, EventArgs e) { //创建Httphelper对象 HttpHelper http = new HttpHelper(); //创建Httphelper参数对象 HttpItem item = new HttpItem() { URL = "http://sufeinet.com",//URL 必需项 Method = "get",//URL 可选项 默认为Get ContentType = "text/html",//返回类型 可选项有默认值 Allowautoredirect = false//默认为False就是不根据重定向自动跳转 }; //请求的返回值对象 HttpResult result = http.GetHtml(item); //获取请求的Cookie string cookie = result.Cookie; //获取302跳转URl string redirectUrl = result.RedirectUrl; item = new HttpItem() { URL = redirectUrl,//URL 必需项 Method = "get",//URL 可选项 默认为Get ContentType = "text/html",//返回类型 可选项有默认值 Cookie = cookie }; //请求的返回值对象 result = http.GetHtml(item); //获取请请求的Html string html = result.Html; //获取请求的Cookie cookie = result.Cookie; }
public static string GetToken() { HttpHelper helper = new HttpHelper(); string url = string.Format(@"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", AppId, AppSecret); string result = helper.Get(url, null); return result; }
protected void Page_Load(object sender, EventArgs e) { //===================================header====================================== //创建Httphelper对象 HttpHelper http = new HttpHelper(); //创建Httphelper参数对象 HttpItem item = new HttpItem() { URL = "http://www.sufeinet.com",//URL 必需项 Method = "get",//URL 可选项 默认为Get ContentType = "text/html",//返回类型 可选项有默认值 //ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值 }; //请求的返回值对象 HttpResult result = http.GetHtml(item); //获取请请求的Html string html = result.Html; //获取请求的Cookie string cookie = result.Cookie; //Header WebHeaderCollection header = result.Header; if (header != null) { string Vary = header["Vary"]; string XCache = header["X-Cache"]; string XServer = header["X-Server"]; } }
protected void Page_Load(object sender, EventArgs e) { //创建Httphelper对象 HttpHelper http = new HttpHelper(); string url = HttpHelper.URLEncode("http://member1.taobao.com/member/user_profile.jhtml?user_id=欧影点点"); //创建Httphelper参数对象 HttpItem item = new HttpItem() { URL =url,//URL 必需项 Method = "get",//URL 可选项 默认为Get ContentType = "text/html",//返回类型 可选项有默认值 }; //请求的返回值对象 HttpResult result = http.GetHtml(item); //获取请请求的Html string html = result.Html; //获取请求的Cookie string cookie = result.Cookie; string parameters = "a=123456&b=456789&c=456456"; //得到一个参数集合 NameValueCollection list = HttpHelper.GetNameValueCollection(parameters); string a = list["a"]; string b = list["b"]; string c = list["c"]; Response.Write(string.Format("a={0}<br/>b={1}<br/>c={2}", a, b, c)); list["a"] = list["a"] + "修改过我"; list["c"] = list["c"] + "修改过我"; a = list["a"]; b = list["b"]; c = list["c"]; Response.Write(string.Format("<br/><br/>a={0}<br/>b={1}<br/>c={2}", a, b, c)); //使用指定的编码对象对 URL 字符串进行编码。 string URLEncode = HttpHelper.URLEncode(parameters); //使用指定的编码对象将 URL 编码的字符串转换为已解码的字符串。 string URLDecode = HttpHelper.URLDecode(URLEncode); Response.Write(string.Format("<br/><br/>URLEncode={0}<br/>URLDecode={1}<br/>", URLEncode, URLDecode)); //使用指定的编码对象对 URL 字符串进行编码。 URLEncode = HttpHelper.URLEncode(parameters, System.Text.Encoding.UTF8); //使用指定的编码对象将 URL 编码的字符串转换为已解码的字符串。 URLDecode = HttpHelper.URLDecode(URLEncode, System.Text.Encoding.UTF8); Response.Write(string.Format("<br/><br/>URLEncode={0}<br/>URLDecode={1}<br/>", URLEncode, URLDecode)); string host = HttpHelper.GetUrlHost("http://www.sufeinet.com"); string ip = HttpHelper.GetUrlIp("http://www.sufeinet.com"); }
/// <summary> /// 获取AccessToken /// </summary> private void GetAccessToken() { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem(); item.URL = string.Format("{0}token?grant_type=client_credential&appid={1}&secret={2}", config.APIUrl, config.AppID, config.AppSecret); string json = http.GetHtml(item); var data = new WeChatData(json); config.AccessToken = data["access_token"]; config.ExpiresIn = DateTime.Now.AddSeconds(data.Get<int>("expires_in")); }
protected void Page_Load(object sender, EventArgs e) { string u = HttpHelper.GetUrlIp("http://www.sufeinet.com"); HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = "http://www.sufeinet.com/template/veikei_dz_life_20130810_plus/images/logo.png?2014-06-06",//URL 必需项 Method = "get",//URL 可选项 默认为Get ResultType = ResultType.Byte }; HttpResult result = http.GetHtml(item); Image img = HttpHelper.GetImage(result.ResultByte); }
protected void Page_Load(object sender, EventArgs e) { ////创建Httphelper对象 //HttpHelper http = new HttpHelper(); ////创建Httphelper参数对象 //HttpItem item = new HttpItem() //{ // URL = "http://www.sufeinet.com",//URL 必需项 // Method = "get",//URL 可选项 默认为Get // ContentType = "text/html",//返回类型 可选项有默认值 // CerPath = "D:\\123.cer" //}; ////请求的返回值对象 //HttpResult result = http.GetHtml(item); ////获取请请求的Html //string html = result.Html; ////获取请求的Cookie //string cookie = result.Cookie; //创建Httphelper对象 HttpHelper http = new HttpHelper(); //创建Httphelper参数对象 HttpItem item = new HttpItem() { URL = "http://www.sufeinet.com",//URL 必需项 Method = "get",//URL 可选项 默认为Get ContentType = "text/html",//返回类型 可选项有默认值 }; item.ClentCertificates = new X509CertificateCollection(); //配置多个证书在这里设置 item.ClentCertificates.Add(new X509Certificate("d:\\123.cer","123456")); //配置多个证书在这里设置 item.ClentCertificates.Add(new X509Certificate("d:\\456.cer")); //请求的返回值对象 HttpResult result = http.GetHtml(item); //获取请请求的Html string html = result.Html; //获取请求的Cookie string cookie = result.Cookie; }
/// <summary> /// 实时天气 /// </summary> /// <returns></returns> public static string GetSK(string id, string name = null, string latitude = null, string longitude = null) { ComLib.LogLib.Log4NetBase.Log("调用GeSK-时间:" + DateTime.Now.ToString()); var ID = id ?? Data.GetID(name ?? BaiduMap.GetCity(latitude, longitude)); if (ID.IsNullOrEmpty()) { return "{\"status\":\"201\",\"message\":\"城市代码获取失败\"}"; } string url = string.Format("http://www.weather.com.cn/data/sk/{0}.html", ID); HttpHelper request = new HttpHelper(); HttpItem item = new HttpItem(); item.URL = url; var jsonhtml = request.GetHtml(item).Html; if (Regex.IsMatch(jsonhtml, "404") || Regex.IsMatch(jsonhtml, "302")) { return "{\"status\":\"201\",\"message\":\"数据获取失败\"}"; } return jsonhtml; }
protected void Page_Load(object sender, EventArgs e) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = "http://workroom.sufeinet.com/Hezuo.aspx",//URL 必需项 }; HttpResult result = http.GetHtml(item); string html = result.Html; string cookie = result.Cookie; string urlll = result.RedirectUrl; Response.Write(result.Html); ////===================================状态码====================================== ////创建Httphelper对象 //HttpHelper http = new HttpHelper(); ////创建Httphelper参数对象 //HttpItem item = new HttpItem() //{ // URL = "http://www.sufeinet.com",//URL 必需项 // Method = "get",//URL 可选项 默认为Get // ContentType = "text/html",//返回类型 可选项有默认值 // //ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值 //}; ////请求的返回值对象 //HttpResult result = http.GetHtml(item); ////获取请请求的Html //string html = result.Html; ////获取请求的Cookie //string cookie = result.Cookie; ////状态码 //HttpStatusCode code = result.StatusCode; ////状态描述 //string Des = result.StatusDescription; //if (code == HttpStatusCode.OK) //{ // //状态为200 //} }
internal APIResponse Call(HttpMethods method, string path, string content, HttpHelper httpHelper) { var request = httpHelper.HttpWebRequest; request.Method = method.ToString(); request.ContentType = "application/json"; request.Headers.Add("Authorization", "Bearer " + this.State.AccessToken); if ((method == HttpMethods.POST || method == HttpMethods.PUT) && !string.IsNullOrEmpty(content)) { using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(content); writer.Close(); } } return GetResponse((HttpWebResponseWrapper)request.GetResponse()); }
protected void Page_Load(object sender, EventArgs e) { ////创建Httphelper对象 HttpHelper http = new HttpHelper(); //创建Httphelper参数对象 HttpItem item = new HttpItem() { URL = "http://www.sufeinet.com",//URL 必需项 Method = "get",//URL 可选项 默认为Get ContentType = "text/html",//返回类型 可选项有默认值 Expect100Continue = false //ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值 }; //请求的返回值对象 HttpResult result = http.GetHtml(item); //获取请请求的Html //string html = result.Html; //List<AItem> alist = HttpHelper.GetAList(html); ////创建Httphelper对象 //HttpHelper http = new HttpHelper(); ////创建Httphelper参数对象 //HttpItem item = new HttpItem() //{ // URL = "http://www.sufeinet.com",//URL 必需项 // Method = "get",//URL 可选项 默认为Get // ContentType = "text/html",//返回类型 可选项有默认值 // //ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值 //}; ////请求的返回值对象 //HttpResult result = http.GetHtml(item); ////获取请请求的Html //string html = result.Html; //List<ImgItem> imglist = HttpHelper.GetImgList(html); ////创建Httphelper对象 //HttpHelper http = new HttpHelper(); ////创建Httphelper参数对象 //HttpItem item = new HttpItem() //{ // URL = "http://www.sufeinet.com",//URL 必需项 // Method = "get",//URL 可选项 默认为Get // ContentType = "text/html",//返回类型 可选项有默认值 // //ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值 //}; ////请求的返回值对象 //HttpResult result = http.GetHtml(item); ////获取请请求的Html //string html = result.Html; //html = HttpHelper.ReplaceNewLine(html); //html = HttpHelper.StripHTML(html); string html = "苏飞论坛"; string str = HttpHelper.GetBetweenHtml(html, "苏", "论坛"); byte[] b = HttpHelper.StringToByte("苏飞"); //可指定编码 b = HttpHelper.StringToByte("苏飞", Encoding.UTF8); string s = HttpHelper.ByteToString(b); s = HttpHelper.ByteToString(b, Encoding.UTF8); string title = HttpHelper.GetHtmlTitle(html); }
protected void Page_Load(object sender, EventArgs e) { //创建Httphelper对象 HttpHelper http = new HttpHelper(); //创建Httphelper参数对象 HttpItem item = new HttpItem() { URL = "http://www.sufeinet.com",//URL 必需项 Method = "post",//URL 可选项 默认为Get ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值 PostDataType = PostDataType.String,//默认为字符串,同时支持Byte和文件方法 PostEncoding = System.Text.Encoding.UTF8,//默认为Default, Postdata = "a=123&c=456&d=789",//Post要发送的数据 }; //请求的返回值对象 HttpResult result = http.GetHtml(item); //获取请请求的Html string html = result.Html; //获取请求的Cookie string cookie = result.Cookie; ////要Post的数据 //string postdate = "a=123&c=456&d=789"; ////将Post数据转为字节数组 //byte[] bytedate = System.Text.Encoding.UTF8.GetBytes(postdate); ////创建Httphelper对象 //HttpHelper http = new HttpHelper(); ////创建Httphelper参数对象 //HttpItem item = new HttpItem() //{ // URL = "http://www.sufeinet.com",//URL 必需项 // Method = "post",//URL 可选项 默认为Get // ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值 // PostDataType = PostDataType.Byte, // PostdataByte = bytedate //}; ////请求的返回值对象 //HttpResult result = http.GetHtml(item); ////获取请请求的Html //string html = result.Html; ////获取请求的Cookie //string cookie = result.Cookie; ////要Post的数据 //string postfile = @"D:\postdata.txt"; ////将Post数据转为字节数组 ////创建Httphelper对象 //HttpHelper http = new HttpHelper(); ////创建Httphelper参数对象 //HttpItem item = new HttpItem() //{ // URL = "http://www.sufeinet.com",//URL 必需项 // Method = "post",//URL 可选项 默认为Get // ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值 // PostDataType = PostDataType.FilePath, // Postdata = postfile //}; ////请求的返回值对象 //HttpResult result = http.GetHtml(item); ////获取请请求的Html //string html = result.Html; ////获取请求的Cookie //string cookie = result.Cookie; }
public static string Do(string userName = "******", string password = "") { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem { URL = "https://ac.ppdai.com/User/Login",//URL 必需项 Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36", Header = new WebHeaderCollection { {"Accept-Encoding"," gzip, deflate, sdch"}, {"Accept-Language","zh-CN,zh;q=0.8"} } }; HttpResult result = http.GetHtml(item); string cookie = result.Cookie; Dictionary<string, string> cks = new Dictionary<string, string>(); foreach (string source in cookie.Split(';').Where(c => !string.IsNullOrEmpty(c))) { if (source.Split('=').Count() > 2) { foreach (string ssource in source.Split(',')) { string[] ss = ssource.Split('='); string key = ss[0].Trim().Split(',').Last(); if (ss.Count() == 2 && !cks.ContainsKey(key.Trim())) { cks.Add(key.Trim(), ss[1].Trim()); } } } else { string[] ss = source.Split('='); string key = ss[0].Trim().Split(',').Last(); if (ss.Count() == 2 && !cks.ContainsKey(key.Trim())) { cks.Add(key.Trim(), ss[1].Trim()); } } } string uniqueid = cks["uniqueid"]; string dtNow = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); cookie = string.Format( "uniqueid={0}; regSourceId=0; referID=0; fromUrl=; referDate={1}; currentUrl=https%3A%2F%2Fac.ppdai.com%2Fuser%2Flogin", uniqueid, HttpUtility.UrlEncode(dtNow)); item = item.GetNextHttpItem("https://ac.ppdai.com/User/Login", cookie); item.Header.Add("X-Requested-With: XMLHttpRequest"); item.ContentType = "application/x-www-form-urlencoded"; item.Referer = "https://ac.ppdai.com/User/Login"; item.Method = "POST"; item.Postdata = string.Format("IsAsync=true&Redirect=&UserName={0}&Password={1}&RememberMe=false", userName, password); result = http.GetHtml(item); cookie = result.Cookie; foreach (string source in cookie.Split(';').Where(c => !string.IsNullOrEmpty(c))) { if (source.Split('=').Count() > 2) { foreach (string ssource in source.Split(',')) { string[] ss = ssource.Split('='); string key = ss[0].Trim().Split(',').Last(); if (ss.Count() == 2 && !cks.ContainsKey(key.Trim())) { cks.Add(key.Trim(), ss[1].Trim()); } } } else { string[] ss = source.Split('='); string key = ss[0].Trim().Split(',').Last(); if (ss.Count() == 2 && !cks.ContainsKey(key.Trim())) { cks.Add(key.Trim(), ss[1].Trim()); } } } cookie = string.Join(";", cks.Select(c => c.Key + "=" + c.Value)); item = item.GetNextHttpItem("http://invest.ppdai.com/PaiMoney/PaiMoneySignin", cookie); item.Accept = "*"; item.ContentType = ""; item.Referer = "http://invest.ppdai.com/account/lend"; item.Postdata = ""; result = http.GetHtml(item); return result.Html; }