C#实现百度ping推送功能的方法
作者:18236992212 发布时间:2023-03-01 18:15:56
标签: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推送功能的方法网站的支持!
来源:http://www.cnblogs.com/qishun/archive/2016/08/07/5746899.html


猜你喜欢
- 推送系统作为通用的组件,存在的价值主要有以下几点会被多个业务项目使用,推送系 * 立维护可降低维护成本推送系统一般都是调用三方api进行推送,
- Activity是最基本的模块,一般称之为"活动",在应用程序中,一个Activity通常就是一个单独的屏幕。简单理解,
- 工厂模式工厂模式顾名思义就是生产实例的工厂,使用工厂模式不会在程序中使用new关键字创建实例。而是将创建对象的细节隐藏,对外提供统一的方法,
- 在新建Java项目时,run运行main方法时,报错 “java: 错误: 无效的源发行版:16”,
- ReferenceWhy using finalizers is a bad idea当在一个类中使用了另外一个实现了IDisposable
- 前言一直对它们之间的关系感到好奇,SpringBoot既然是Spring的封装,那么SpringBoot在初始化时应该也会有Bean的加载,
- 在java.lang.Runtime.exec的使用中,我们经常会用到将重定向命令执行的输入/结果或者将错误信息读取出来.那么,在使用过程中
- 使用 try/catch 处理异常try-catch 块的用途是捕捉和处理工作代码所生成的异常。 有些异常可以在 catch 块中处理,解决
- 本文实例为大家分享了Android倒计时进度条展示的具体代码,供大家参考,具体内容如下效果预览源代码传送门:https://github.c
- 大家都知道使用java反射可以在运行时动态改变对象的行为,甚至是private final的成员变量,但并不是所有情况下,都可以修改成员变量
- 之前讲到了自定义Adapter传递给ListView时,因为ListView的View回收,需要注意当ListView列表项中包含有带有状态
- 本文实例讲述了C#修改及重置电脑密码DirectoryEntry实现方法。分享给大家供大家参考。具体如下:C#修改电脑密码方法如下:///
- 金山公司面试题:一个字符串中可能包含a~z中的多个字符,如有重复,如String data="aavzcadfdsfsdhshgW
- 前言通过本文你可以了解List的五种遍历方式及各自性能和foreach及Iterator的实现,加深对ArrayList和LinkedLis
- 实体例子public class Person { private String name; &nb
- 在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启动的,而不需要另
- 对象类型转换分为向上转型和向下转型(强制对象转型)。 向上转型是子对象向父对象转型的过程,例如猫类转换为动物类;向下转型是强制转型实现的,是
- 前言Snackbar和Toast相似,都是为了给用户提供交互信息,Snackbar是固定在底部的,显示时从下往上滑出要使用Snackbar,
- 本文实例讲述了C#使用oledb操作excel文件的方法。分享给大家供大家参考。具体分析如下:不管什么编程语言都会提供操作Excel文件的方
- 本文实例为大家分享了Java身份证号码校验工具类的具体代码,供大家参考,具体内容如下import java.text.ParseExcept