SeoHelper专门给各大搜索引擎提供操作帮助的类Helper
此类会持续更新,并加入到我的基类库,完全开源免费,有需要的直接拿去。目前只提供了百度原创接口提交和Ping百度提交
其实有了这两种大家对于百度收录已经不是问题了。
直接上类
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace Util.Helper
{
/// <summary>
/// 专门给各大搜索引擎提供操作帮助的类
/// 创建人:苏飞
/// 时 间:2015-10-28
/// 更新人:苏飞
/// 更新网址:http://www.sufeinet.com/thread-14254-1-1.html
/// </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
{
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提交给百度原创提交接口,需要自行申请Taken
/// </summary>
/// <param name="curl">要发送的url注意带上http://</param>
/// <param name="token">TzIJxrHBBTH9VdsX默认的Token值</param>
/// <returns>成功true 否则为False</returns>
public static Boolean OriginalPingBaidu(string curl, string token = "TzIJxrHBBTH9VdsX")
{
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;
}
}
}
|