国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現百度ping推送功能的方法

2020-01-24 01:01:32
字體:
來源:轉載
供稿:網友

網站優化必做的事情之一,百度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.htmlstring 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推送功能的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平遥县| 综艺| 巴彦县| 大同县| 娱乐| 凌源市| 枣强县| 巨野县| 壶关县| 安吉县| 水富县| 安徽省| 博野县| 九台市| 岫岩| 锦州市| 龙泉市| 新平| 阳曲县| 湟中县| 鱼台县| 武宁县| 玉溪市| 临漳县| 龙游县| 龙口市| 河源市| 蕉岭县| 道孚县| 岫岩| 时尚| 陆良县| 且末县| 桂林市| 柘荣县| 施甸县| 永靖县| 永靖县| 永平县| 象州县| 蓬溪县|