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# 自动提交到百度ping服务
C# 自动提交到百度ping服务 今天无意之间看到百度站长中有这个ping服务(孤陋寡闻呀).... 那什么什么是Ping服务 ping是基于XML_RPC标准协议的更新通告服务,用于博客把内容更新快 ...
- js/jQuery实现类似百度搜索功能
一.页面代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...
- JS 实现百度搜索功能
今天我们来用JS实现百度搜索功能,下面上代码: HTML部分: <!DOCTYPE html> <html> <head> <meta charset=&qu ...
- 原生JS实现百度搜索功能
今天呢给大家分享一下自己用原生JS做的一个百度搜索功能,下面上代码: <!DOCTYPE html> <html> <head> <meta charset= ...
- Linux下实现ping功能
实现ping功能,就肯定要用到ping命令,那么在Linux下ping命令为: ping [-dfnqrRv][-c<完成次数>][-i<间隔秒数>][-I<网络界面&g ...
- Java实现ping功能的三种方法及Linux的区分
前大半部份转自:https://blog.csdn.net/futudeniaodan/article/details/52317650 检测设备的运行状态,有的是使用ping的方式来检测的.所以需要 ...
- 009——VUE中watch监听属性变化实现类百度搜索栏功能
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 你知道PING功能是怎么实现的吗
以太网的协议有层,而每层都包含有更多的协议.所谓协议,通俗的讲就是通信双方约定的规则. 今天我们介绍一些一个听起来陌生却有很常用的协议,ICMP协议. ICMP是(Internet Control ...
- 如何开放 Azure 虚拟机 Ping 功能
前言 文章<使用 PsPing & PaPing 进行 TCP 端口连通性测试>中提到,ICMP 协议的数据包无法通过 Azure 的防火墙和负载均衡器,所以不能直接使用 Ping ...
随机推荐
- HDU 4678 Mine(博弈)
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submi ...
- uboot移植之迷雾解码
按照蜗窝科技的步骤执行 一.有关硬件描述的填空题 1)CPU上电后,从哪种设备( BOOTROM )的哪个地址( 0x0000_0000 )开始执 ...
- AIX系统软件安装问题
一.安装软件时一定要cd到介质目录中 二.选择accept new licence 三.更新系统时避免使用updata_all,要手动选择出要更新的软件 四.oracle11G的rac还要用到open ...
- Flsak中的socket是基于werkzeug实现的。
from werkzeug.serving import run_simple from werkzeug.wrappers import Request,Respinse @Request.appl ...
- 17 安全字符串 System.Security.SecureString
- 数据库智能管理助手-CloudDBA
摘要:阿里云CloudDBA主要分为离线分析和在线分析两种功能.帮助用户节省成本,定位问题,分析原因并推荐解决方法.CloudDBA可以做到实时诊断,离线诊断和SQL优化.并且通过MySQL的参数调优 ...
- 微信公众号号开发(Java)
参考:http://www.cnblogs.com/fengzheng/p/5023678.html http://www.cnblogs.com/xdp-gacl/p/5151857.html 一: ...
- python 全栈开发,Day53(jQuery的介绍,jQuery的选择器,jQuery动画效果)
01-jQuery的介绍 1.为什么要使用jQuery 在用js写代码时,会遇到一些问题: window.onload 事件有事件覆盖的问题,因此只能写一个事件. 代码容错性差. 浏览器兼容性问题. ...
- php count_chars()函数 语法
php count_chars()函数 语法 作用:返回一个字符串,包含所有在字符串中使用过的不同字符.直线电机选型 语法:count_chars(string,mode) 参数: 参数 描述 str ...
- C语言 | 线段树
#include<stdio.h> #define MAX_LEN 1000 void build_tree(int arr[],int tree[],int node,int start ...