C#实现百度ping推送功能的方法
作者:18236992212 时间:2023-03-01 18:15:56
网站优化必做的事情之一,百度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
标签:c#,百度,ping
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
取消Android Studio项目与SVN关联的方法
2022-09-14 11:48:45
![](https://img.aspxhome.com/file/2023/2/139332_0s.png)
Java实现图片验证码具体代码
2021-06-30 13:16:35
![](https://img.aspxhome.com/file/2023/9/60989_0s.jpg)
java使用Filter实现自动登录的方法
2022-09-09 15:46:47
Java特性队列和栈的堵塞原理解析
2023-10-13 14:15:55
java 动态生成SQL的实例讲解
2021-05-25 18:26:06
详解java中各类锁的机制
2022-08-01 06:48:56
![](https://img.aspxhome.com/file/2023/3/71233_0s.jpg)
再议C#中的装箱与拆箱的问题详解
2022-09-30 03:45:40
Maven实战之搭建Maven私服和镜像的方法(图文)
2023-11-27 22:27:06
![](https://img.aspxhome.com/file/2023/9/60249_0s.png)
Android WebView支持input file启用相机/选取照片功能
2023-09-15 07:56:48
Android自定义ActionProvider ToolBar实现Menu小红点
2022-09-09 05:07:30
![](https://img.aspxhome.com/file/2023/9/98649_0s.gif)
深入解析Java接口(interface)的使用
2022-05-07 07:50:51
Android应用开发中使用GridView网格布局的代码示例
2023-11-09 20:23:36
![](https://img.aspxhome.com/file/2023/8/120088_0s.png)
Java卡片布局管理器解释及实例
2022-03-12 18:26:19
Java NIO:浅析IO模型_动力节点Java学院整理
2022-01-17 17:07:38
![](https://img.aspxhome.com/file/2023/8/65178_0s.png)
JAVA JDK8 List分组获取第一个元素的方法
2021-06-24 13:07:51
SpringBoot雪花算法主键ID传到前端后精度丢失问题的解决
2022-07-18 02:30:47
![](https://img.aspxhome.com/file/2023/8/130908_0s.png)
slf4j与jul、log4j1、log4j2、logback的集成原理
2023-01-31 18:01:47
![](https://img.aspxhome.com/file/2023/2/68552_0s.png)
Spring Boot整合流控组件Sentinel的场景分析
2023-06-22 19:27:53
![](https://img.aspxhome.com/file/2023/0/57600_0s.jpg)
详解Java8中CompletableFuture类的使用
2022-06-28 17:39:43
JAVA OutputStreamWriter流的实现
2021-08-12 19:45:47