C#發(fā)送請求Ping百度收錄,百度搜索引擎SeoHelper幫助類
此SeoHelper幫助類:
提供直接ping百度收錄幫助類,直接把網(wǎng)站Url地址提交給百度原創(chuàng)提交接口
要把站點(diǎn)做到百度秒收,站長們可要下工夫嘍 ,下面這個(gè)幫助類,還望廣大站長好好利用,
可按照自己的需求隨意更改方法哦
幫助類中用到的Post請求幫助類下載地址:
點(diǎn)我下載HttpHelper幫助類庫 輕松實(shí)現(xiàn)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發(fā)送到Ping百度http://ping.baidu.com/ping.html /// </summary> /// <param name="url">要發(fā)送的url注意帶上http://</param> /// <returns>成功true 否則為False</returns> public static Boolean PingBaidu(string url) { try { //別忘了配置 <!--ping百度開關(guān)--> <add key="SeoPingBaidu" value="1" /> //也可自行修改本方法滿足自身需求 string obt = System.Configuration.ConfigurationManager.AppSettings["SeoPingBaidu"]; if (obt == "1") { //提交到百度原創(chuàng) 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 必需項(xiàng) Method = "POST",//URL 可選項(xiàng) 默認(rèn)為Get Referer = "http://ping.baidu.com/ping.html",//來源URL 可選項(xiàng) Postdata = sb.ToString(),//Post數(shù)據(jù) 可選項(xiàng)GET時(shí)不需要寫 ProtocolVersion = HttpVersion.Version10, }; HttpResult result = http.GetHtml(item); if (result.Html.Contains("<int>0</int>")) { return true; } } } catch { } return false; } /// <summary> ///直接網(wǎng)站Url地址提交給百度原創(chuàng)提交接口,Token需要自行申請,下面使用的是百度默認(rèn)token /// </summary> /// <param name="curl">要發(fā)送的url網(wǎng)址必須帶上http://</param> /// <param name="token">DokEJg20ZhWhMqbT默認(rèn)的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 必需項(xiàng) Method = "POST",//URL 可選項(xiàng) 默認(rèn)為Get Referer = curl,//來源URL 可選項(xiàng) Postdata = curl,//Post數(shù)據(jù) 可選項(xiàng)GET時(shí)不需要寫 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#發(fā)送請求Ping百度收錄,百度搜索引擎SeoHelper幫助類