本文整理汇总了C#中HttpHelper.GetHtml方法的典型用法代码示例。如果您正苦于以下问题:C# HttpHelper.GetHtml方法的具体用法?C# HttpHelper.GetHtml怎么用?C# HttpHelper.GetHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHelper
的用法示例。
在下文中一共展示了HttpHelper.GetHtml方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMessage
/// <summary>
/// 发送短信
/// </summary>
/// <param name="receiver">短信接收人手机号码</param>
/// <param name="content">短信内容</param>
/// <returns>发送状态</returns>
public static SMSCode SendMessage(string receiver, string content)
{
try
{
//创建Httphelper对象
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL = string.Format("{0}?phone={1}&content=验证码:{2}", SmsAPI, receiver, content),//URL 必需项
Method = "get",//可选项 默认为Get
ContentType = "text/plain"//返回类型 可选项有默认值 ,
};
item.Header.Add("apikey", Apikey);
//请求的返回值对象
HttpResult result = http.GetHtml(item);
JObject jo = JObject.Parse(result.Html);
JToken value = null;
if (jo.TryGetValue("result", out value))
{
return EnumHelper.IntToEnum<SMSCode>(Convert.ToInt32(value.ToString()));
}
return SMSCode.SystemBusy;
}
catch (Exception ex)
{
LogHelper.WriteLog("短信发送失败", ex);
return SMSCode.Exception;
}
}
示例2: GetAccessTokenNoCache
/// <summary>
/// 获取每次操作微信API的Token访问令牌
/// </summary>
/// <param name="corpid">企业Id</param>
/// <param name="corpsecret">管理组的凭证密钥</param>
/// <returns></returns>
public string GetAccessTokenNoCache(string corpid, string corpsecret)
{
var url = string.Format("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}",
corpid, corpsecret);
HttpHelper helper = new HttpHelper();
string result = helper.GetHtml(url);
string regex = "\"access_token\":\"(?<token>.*?)\"";
string token = CRegex.GetText(result, regex, "token");
return token;
}
示例3: GetMinFreeShipping
public void GetMinFreeShipping(Site site)
{
logInfo logInfo = new logInfo();
logInfo.Location = this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;
//get the minimun purchase amount for free shipping from it's F&Q page
string url = "https://jet.com/help-center/shipping-and-returns";
HttpItem httpItem = new HttpItem();
httpItem.Cookie = string.Empty;
httpItem.Method = "GET";
httpItem.Header = null;
httpItem.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
httpItem.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36";
//httpItem.Timeout = 60000 * 5;
httpItem.URL = url;
HttpHelper httpHelper = new HttpHelper();
HttpResult httpResult = null;
try
{
httpResult = httpHelper.GetHtml(httpItem);
if (httpResult == null)
{
logInfo.KeyInfo = "Remote HTML is null (timeout etc.)";
Log4Helper.WarningLog(logInfo);
}
else
{
if (httpResult.StatusCode != System.Net.HttpStatusCode.OK)
{
logInfo.KeyInfo = "Remote HTML is null (timeout etc.)";
Log4Helper.WarningLog(logInfo);
}
else
{
string content = httpResult.Html;
if (content.Length < 200)
{
return;
}
HtmlHelper html = new HtmlHelper(content);
var fq_node = html.GetNodeByXPath("//div[@class='page_content']/h1");
var ans = html.GetNodesByXPath("following-sibling::p", fq_node);
Regex minfreeshipping_pattern = new Regex(@"orders\sover\s\$(\d+)");
Regex shippingfee_pattern = new Regex(@"fixed\sshipping\sfee\sof\s\$(\d+(\.\d+)?)");
int match_min = 0;
int match_fee = 0;
foreach(HtmlNode a in ans)
{
if(minfreeshipping_pattern.Match(a.InnerText).Success)
{
min_shipping = Convert.ToSingle(minfreeshipping_pattern.Match(a.InnerText).Groups[1].Value);
match_min = 1;
}
if (shippingfee_pattern.Match(a.InnerText).Success)
{
fee_shipping = Convert.ToSingle(shippingfee_pattern.Match(a.InnerText).Groups[1].Value);
match_fee = 1;
}
if(match_min==1&&match_fee==1)
{
continue;
}
}
}
}
}
catch (Exception ex)
{
logInfo.KeyInfo = "Could not get remote HTML";
Log4Helper.ErrorLog(logInfo);
}
}
示例4: GetHTML
/// <summary>
/// 获取页面html内容
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private static string GetHTML(string url, string ProxyIp)
{
try
{
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL = url,//URL 必需项
Method = "get",//可选项 默认为Get
ContentType = "text/html",//返回类型 可选项有默认值
ProxyIp = ProxyIp
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
return result.Html;
}
catch (Exception)
{
return "<HTML></HTML>";
}
}
示例5: Excute
public string Excute(WeChatConfig config, WeChatData data)
{
//var msg = new
//{
// button = new object[]
// {
// new {type="click",name="定位监控",key="CLICK_DWJK" },
// new {type="click",name="里程报表",key="CLICK_LCBB" },
// new
// {
// name="账号",
// sub_button=new object[]
// {
// new {type="click",name="绑定账号",key="CLICK_BDZH" },
// new {type="click",name="取消绑定",key="CLICK_QXBD" }
// }
// }
// }
//};
var msg = new
{
button = new object[]
{
new
{
name="查车",
sub_button=new object[]
{
new {type="click",name="定位监控",key="CLICK_DWJK" },
new {type="click",name="里程报表",key="CLICK_LCBB" }
}
},
new {type="click",name="设防撤防",key="CLICK_SFCF" },
new
{
name="账号",
sub_button=new object[]
{
new {type="click",name="绑定账号",key="CLICK_BDZH" },
new {type="click",name="取消绑定",key="CLICK_QXBD" }
}
}
}
};
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem();
item.URL = string.Format("{0}menu/create?access_token={1}", config.APIUrl, config.AccessToken);
item.Method = "POST";
item.Encoding = "utf-8";
item.ContentType = "application/x-www-form-urlencoded";
item.Postdata = msg.ToJsonString();
string result = http.GetHtml(item);
return result;
}
示例6: sendTextMessageToWechat
public HttpResult sendTextMessageToWechat(String toUser, String content, string corpId, String Wechat_Secret, int agentid)
{
WechatUtil wechatUtil = new WechatUtil();
String accessToken = wechatUtil.GetAccessTokenNoCache(corpId, Wechat_Secret);
var msgUrl = string.Format("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}", accessToken);
var msgData = new
{
touser = toUser,
msgtype = "text",
agentid = agentid,
safe = 0,
text = new
{
content = content
}
};
string msgJson = JsonConvert.SerializeObject(msgData, Formatting.Indented);
HttpHelper httpHelper = new HttpHelper();
HttpItem item = new HttpItem()
{
Encoding = Encoding.GetEncoding("UTF-8"),
URL = msgUrl,
Method = "post",//URL 可选项 默认为Get
Postdata = msgJson,
PostEncoding = Encoding.GetEncoding("UTF-8")//可以发送中文消息了,开心
};
HttpResult result = httpHelper.GetHtml(item);
return result;
}