网站优化必做的事情之一,百度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. springboot+UEditor图片上传

    springboot+UEDitor百度编辑器整合图片上记录于此 1.下载ueditor插件包,解压到static/ueditor目录下 2.在你所需实现编辑器的页面引用三个JS文件 1)  uedi ...

  2. alert(1) to win 10

  3. 了解卷积神经网络如何使用TDA学习

    在我之前的文章中,我讨论了如何对卷积神经网络(CNN)学习的权重进行拓扑数据分析,以便深入了解正在学习的内容以及如何学习它. 这项工作的重要性可归纳如下: 它使我们能够了解神经网络如何执行分类任务. ...

  4. Mac xlwings aem.aemsend.EventError: Command failed: The user has declined permission. (-1743)

    aem.aemsend.EventError: Command failed: The user has declined permission. (-1743) 关于mac pycharm 使用xl ...

  5. Java浏览器弹出下载框,多个文件导出压缩包

    项目里一直有这个功能,也一直没怎么注意,今天研究了一下 依据逻辑往下走: 首先是要下载的ajax的Java方法,只有返回值需要设定一下,其他的不用管: Map<String, Object> ...

  6. 用jquery实现图片轮播

    用jquery简单实现图片轮播效果,代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  7. BZOJ 1597: [Usaco2008 Mar]土地购买 动态规划 + 斜率优化

    Code: #include<bits/stdc++.h> #define maxn 1000000 #define ll long long #define x(i) (b[i+1]) ...

  8. [luogu]P1168 中位数[堆]

    [luogu]P1168 中位数 题目描述 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[3], …, A[2k - 1]的中位数.即前1 ...

  9. Android解析编译之后的所有文件(so,dex,xml,arsc)格式

    我们在之前一篇一篇介绍了如何解析Android中编译之后的所有文件格式,所有的工作都完成了,这里我们就来做个总结,我们为什么要做这些工作: 第一篇:解析so文件格式 点击进入 这里我们解析so文件,主 ...

  10. 【SpringBoot】 项目中运用的一些技巧,mybatis-plus 自动编译等(持续更新)

    前言 本文将总结项目中用到的一些springboot 的技巧,持续更新. Mybatis-Plus 的运用 使用原因: 主要是节省了Mapper层的编写,通过继承BaseMapper可以直接调用通用的 ...