C#實(shí)現(xiàn)百度ping推送功能的方法
網(wǎng)站優(yōu)化必做的事情之一,百度ping,主動(dòng)推送給百度
文章添加時(shí)調(diào)用百度推送方法
//保存
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (action == DTEnums.ActionEnum.Edit.ToString()) //修改
{
ChkAdminLevel("channel_" + this.channel_name + "_list", DTEnums.ActionEnum.Edit.ToString()); //檢查權(quán)限
if (!DoEdit(this.id))
{
JscriptMsg("保存過程中發(fā)生錯(cuò)誤啦!", string.Empty);
return;
}
JscriptMsg("修改信息成功!", "article_list.aspx?channel_id=" + this.channel_id);
}
else //添加
{
ChkAdminLevel("channel_" + this.channel_name + "_list", DTEnums.ActionEnum.Add.ToString()); //檢查權(quán)限
int id=DoAdd(); //此 id為添加文章返回的 此篇文章的id 需要修改添加文章的方法 返回id if (!(id>0))
{
JscriptMsg("保存過程中發(fā)生錯(cuò)誤!", 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>
/// 百度相關(guān)類
/// </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);
// 設(shè)置提交的相關(guān)參數(shù)
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;
// 提交請(qǐng)求數(shù)據(jù)
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#實(shí)現(xiàn)百度ping推送功能的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Unity3D實(shí)現(xiàn)相機(jī)跟隨控制
這篇文章主要為大家詳細(xì)介紹了Unity3D實(shí)現(xiàn)相機(jī)跟隨控制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07
詳解C#讀取Appconfig中自定義的節(jié)點(diǎn)
我們往往需要在App.config中自定義一些節(jié)來滿足實(shí)際需要,而不依賴于App.config的appSettings,下面通過一個(gè)簡(jiǎn)單的實(shí)例來說明自定義配置節(jié)點(diǎn)的設(shè)置與讀取2015-06-06
C#讀取word中表格數(shù)據(jù)的方法實(shí)現(xiàn)
本文主要介紹了C#讀取word中表格數(shù)據(jù)的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
C#實(shí)現(xiàn)通過winmm.dll控制聲音播放的方法
這篇文章主要介紹了C#實(shí)現(xiàn)通過winmm.dll控制聲音播放的方法,很實(shí)用的功能,需要的朋友可以參考下2014-08-08
C#實(shí)現(xiàn)在兩個(gè)數(shù)字之間生成隨機(jī)數(shù)的方法
這篇文章主要介紹了C#實(shí)現(xiàn)在兩個(gè)數(shù)字之間生成隨機(jī)數(shù)的方法,在一些特殊場(chǎng)景會(huì)用到哦,需要的朋友可以參考下2014-08-08
C#中把日志導(dǎo)出到txt文本的簡(jiǎn)單實(shí)例
這篇文章介紹了C#中把日志導(dǎo)出到txt文本的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-10-10
C#程序連接數(shù)據(jù)庫及讀取數(shù)據(jù)庫中字段的簡(jiǎn)單方法總結(jié)
包括C#連接Access、Oracle或者SQL Server,這里整理了一些C#連接數(shù)據(jù)庫及從讀取數(shù)據(jù)庫中字段的簡(jiǎn)單方法總結(jié),需要的朋友可以參考下2016-05-05

