网站优化必做的事情之一,百度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功能的更多相关文章

  1. C# 自动提交到百度ping服务

    C# 自动提交到百度ping服务 今天无意之间看到百度站长中有这个ping服务(孤陋寡闻呀).... 那什么什么是Ping服务 ping是基于XML_RPC标准协议的更新通告服务,用于博客把内容更新快 ...

  2. js/jQuery实现类似百度搜索功能

    一.页面代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  3. JS 实现百度搜索功能

    今天我们来用JS实现百度搜索功能,下面上代码: HTML部分: <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  4. 原生JS实现百度搜索功能

    今天呢给大家分享一下自己用原生JS做的一个百度搜索功能,下面上代码: <!DOCTYPE html> <html> <head> <meta charset= ...

  5. Linux下实现ping功能

    实现ping功能,就肯定要用到ping命令,那么在Linux下ping命令为: ping [-dfnqrRv][-c<完成次数>][-i<间隔秒数>][-I<网络界面&g ...

  6. Java实现ping功能的三种方法及Linux的区分

    前大半部份转自:https://blog.csdn.net/futudeniaodan/article/details/52317650 检测设备的运行状态,有的是使用ping的方式来检测的.所以需要 ...

  7. 009——VUE中watch监听属性变化实现类百度搜索栏功能

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. 你知道PING功能是怎么实现的吗

    以太网的协议有层,而每层都包含有更多的协议.所谓协议,通俗的讲就是通信双方约定的规则. 今天我们介绍一些一个听起来陌生却有很常用的协议,ICMP协议. —ICMP是(Internet Control ...

  9. 如何开放 Azure 虚拟机 Ping 功能

    前言 文章<使用 PsPing & PaPing 进行 TCP 端口连通性测试>中提到,ICMP 协议的数据包无法通过 Azure 的防火墙和负载均衡器,所以不能直接使用 Ping ...

随机推荐

  1. dirname 显示文件或目录路径

    1. 命令功能 dirname 去除文件名中非目录部分,仅显示与目录有关部分.dirname读取指定路径名保留最后一个/及其后面部分的字符,删除其他部分,并把结果到标准输出.如果最后一个/后无字符,d ...

  2. Java中最基本的集合接口:初识Collection

    Collection接口 Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的元素(Elements). 一些 Collection允许相同的 ...

  3. File类常用方法和枚举

    新建一个file对象: File f = new File("F:\\01.JAVA基础300集\\05_常用类\\122.File类的使用.mp4"); (文件路径也可以用&qu ...

  4. 1N4148

    摘自http://baike.baidu.com/link?url=0iTO7zZvHpCeJiZurTPpjDT95YdJu7cKdTeCWfol36b4JG5ii15leQ7K4wJWAZIBNb ...

  5. Rabbit给单独的消息设置超时

    /** * 发送消息 * @param user */@RequestMapping(value = prefix+"/setRabbitMessage", method = Re ...

  6. hdu 6205: card card card【输入挂】

    题目链接 感谢 http://blog.csdn.net/txgang/article/details/77568491 以下供参考 getchar读入法 2683MS FastIO法 MX=1e2 ...

  7. python学习笔记(十八)python操作excel

    python操作excel需要安装通过pip安装xlwt, xlrd这两个模块: pip install xlwt pip insall xlrd 操作excel ,写入excel: import x ...

  8. Jira插件安装

    以下操作需要反编译 1.反编译的jar包 1)E:\JIRA安装路径\atlassian-jira\WEB-INF\atlassian-bundled-plugins\atlassian-univer ...

  9. PHPExcel 之常用功能

    PHPExcel基本操作: 定义EXCEL实体 即定义一个PHPEXCEL对象,并设置EXCEL对象内显示内容 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  10. 20180805-Java DataInputStream类

    DataInputStream dis = DataInputStream(InputStream in); 下面的例子演示了DataInputStream和DataOutputStream的使用,该 ...