C#实现百度ping推送功能的方法
更新时间:2016年08月08日 11:56:06 作者:18236992212
百度ping是网站优化必做的事情,这样才能主动推送给百度,那么基于代码是如何实现百度推送方法呢?下文小编给大家带来了C#实现百度ping推送功能的方法,非常不错,感兴趣的朋友一起学习吧
网站优化必做的事情之一,百度ping,主动推送给百度
文章添加时调用百度推送方法
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { if (action == DTEnums.ActionEnum.Edit.ToString()) //修改 { ChkAdminLevel("channel_" + this.channel_name + "_list", DTEnums.ActionEnum.Edit.ToString()); //检查权限 if (!DoEdit(this.id)) { JscriptMsg("保存过程中发生错误啦!", string.Empty); return; } JscriptMsg("修改信息成功!", "article_list.aspx?channel_id=" + this.channel_id); } else //添加 { ChkAdminLevel("channel_" + this.channel_name + "_list", DTEnums.ActionEnum.Add.ToString()); //检查权限 int id=DoAdd(); //此 id为添加文章返回的 此篇文章的id 需要修改添加文章的方法 返回id if (!(id>0)) { JscriptMsg("保存过程中发生错误!", string.Empty); return; } //获取频道模板名称 if (channel_id == 13 || channel_id == 16 || channel_id == 18 || channel_id == 25 || channel_id == 6) { string channelTemp = new BLL.channel().GetModel(this.channel_id).name.ToString(); string articleUrl = new BasePage().linkurl(channelTemp + "_show", id); string[] url = new string[100]; url[1] = "http://www.qishunnet.com" + articleUrl;//例如生成的url如http://www.qishunnet.com/knowledge_show_132.html string info = DTcms.Common.BaiDu.sendUrlToBaidu(url); JscriptMsg("添加信息成功!", "article_list.aspx?channel_id=" + this.channel_id + "&message=添加信息成功!百度推送返回信息=" + info + "url:" + url[1]); return; } JscriptMsg("添加信息成功!", "article_list.aspx?channel_id=" + this.channel_id); } }
common类库增加百度ping方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTcms.Common { /// <summary> /// 百度相关类 /// </summary> public class BaiDu { /// <summary> /// 推送链接至百度 /// </summary> /// <param name="urls">链接集合</param> /// <returns></returns> public static string sendUrlToBaidu(string[] urls) { try { string formUrl = " http://data.zz.baidu.com/urls?site=www.qishunnet.com&token=FdSmdb3LRa4JitQp"; string formData = ""; foreach (string url in urls) { formData += url + "\n"; } byte[] postData = System.Text.Encoding.UTF8.GetBytes(formData); // 设置提交的相关参数 System.Net.HttpWebRequest request = System.Net.WebRequest.Create(formUrl) as System.Net.HttpWebRequest; System.Text.Encoding myEncoding = System.Text.Encoding.UTF8; request.Method = "POST"; request.KeepAlive = false; request.AllowAutoRedirect = true; request.ContentType = "text/plain"; request.UserAgent = "curl/7.12.1"; request.ContentLength = postData.Length; // 提交请求数据 System.IO.Stream outputStream = request.GetRequestStream(); outputStream.Write(postData, 0, postData.Length); outputStream.Close(); System.Net.HttpWebResponse response; System.IO.Stream responseStream; System.IO.StreamReader reader; string srcString; response = request.GetResponse() as System.Net.HttpWebResponse; responseStream = response.GetResponseStream(); reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding("UTF-8")); srcString = reader.ReadToEnd(); string result = srcString; //返回值赋值 reader.Close(); return result; } catch (Exception ex) { return ex.Message; } } } }
以上所述是小编给大家介绍的C#实现百度ping推送功能的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
相关文章
浅谈C# 非模式窗体show()和模式窗体showdialog()的区别
下面小编就为大家带来一篇浅谈C# 非模式窗体show()和模式窗体showdialog()的区别。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2016-07-07C#中使用IFormattable实现自定义格式化字符串输出示例
这篇文章主要介绍了C#中使用IFormattable实现自定义格式字符串输出示例,本文直接给出实例代码,需要的朋友可以参考下2015-06-06Datagridview使用技巧(9)Datagridview的右键菜单
这篇文章主要为大家详细介绍了Datagridview使用技巧,Datagridview的右键菜单,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-05-05
最新评论