C#发送请求Ping百度收录,百度搜索引擎SeoHelper帮助类
此SeoHelper帮助类:
提供直接ping百度收录帮助类,直接把网站Url地址提交给百度原创提交接口
要把站点做到百度秒收,站长们可要下工夫喽 ,下面这个帮助类,还望广大站长好好利用,
可按照自己的需求随意更改方法哦
帮助类中用到的Post请求帮助类下载地址:
点我下载HttpHelper帮助类库 轻松实现Post和Get请求
SeoHelper源码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; namespace JsonsTeamUtil.Helper { /// <summary> /// 百度搜索引擎提交帮助类:提供直接ping百度收录帮助类 /// </summary> public class SeoHelper { /// <summary> ///直接将提供的Url发送到Ping百度http://ping.baidu.com/ping.html /// </summary> /// <param name="url">要发送的url注意带上http://</param> /// <returns>成功true 否则为False</returns> public static Boolean PingBaidu(string url) { try { //别忘了配置 <!--ping百度开关--> <add key="SeoPingBaidu" value="1" /> //也可自行修改本方法满足自身需求 string obt = System.Configuration.ConfigurationManager.AppSettings["SeoPingBaidu"]; if (obt == "1") { //提交到百度原创 bool ret = OriginalPingBaidu(url); return ret; } else if (obt == "2") { StringBuilder sb = new StringBuilder(); sb.Append("<?xml version=\"1.0\"?>"); sb.Append("<methodCall>"); sb.Append("<methodName>weblogUpdates.ping</methodName>"); sb.Append("<params>"); sb.Append("<param>"); sb.Append("<value><string>" url "</string></value>"); sb.Append("</param><param><value><string>" url "</string></value>"); sb.Append("</param>"); sb.Append("</params>"); sb.Append("</methodCall>"); HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = "http://ping.baidu.com/ping/RPC2",//URL 必需项 Method = "POST",//URL 可选项 默认为Get Referer = "http://ping.baidu.com/ping.html",//来源URL 可选项 Postdata = sb.ToString(),//Post数据 可选项GET时不需要写 ProtocolVersion = HttpVersion.Version10, }; HttpResult result = http.GetHtml(item); if (result.Html.Contains("<int>0</int>")) { return true; } } } catch { } return false; } /// <summary> ///直接网站Url地址提交给百度原创提交接口,Token需要自行申请,下面使用的是百度默认token /// </summary> /// <param name="curl">要发送的url网址必须带上http://</param> /// <param name="token">DokEJg20ZhWhMqbT默认的Token值</param> /// <returns>成功true 否则为False</returns> public static Boolean OriginalPingBaidu(string curl, string token = "DokEJg20ZhWhMqbT") { string url = string.Format("http://data.zz.baidu.com/urls?site={0}&token={1}", new Uri(curl).Host, token); HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = url,//URL 必需项 Method = "POST",//URL 可选项 默认为Get Referer = curl,//来源URL 可选项 Postdata = curl,//Post数据 可选项GET时不需要写 ProtocolVersion = HttpVersion.Version10, ContentType = "text/plain", UserAgent = "curl/7.12.1" }; HttpResult result = http.GetHtml(item); if (result.Html.Contains("\"success\":1")) { return true; } return false; } } }
原文链接:C#发送请求Ping百度收录,百度搜索引擎SeoHelper帮助类