As I recently have explored the world of blogging, I found myself looking for code that would allow me to ping sites like Technorati.com and Feedburner.com. What I found was a nice piece of code in C# by Will Asrari. You can view the C# version of this code at http://www.willasrari.com/blog/programmatically-ping-technorati-using-c/00098.aspx.
However, I program in VB.NET so I converted the code and added the ability to ping several services. The following code will allow you to ping Technorati as well as the other links that are listed. All you need to do is add a call to the procedure in your submit or save event for blog entries.
Public Shared Sub PingSites() Dim listToPing As New ArrayList Dim pingURL As String = "" Dim blogURL As String = "http://www.jeremywadsworth.com" Dim blogName As String = "Jeremy Wadsworth"
With listToPing .Add("http://rpc.technorati.com/rpc/ping") .Add("http://api.feedster.com/ping") .Add("http://ping.feedburner.com") .Add("http://blog.goo.ne.jp/XMLRPC") .Add("http://ping.blo.gs/") .Add("http://ping.bloggers.jp/rpc/") .Add("http://ping.blogmura.jp/rpc/") .Add("http://ping.cocolog-nifty.com/xmlrpc") .Add("http://ping.syndic8.com/xmlrpc.php") .Add("http://rpc.blogbuzzmachine.com/RPC2") .Add("http://rpc.blogrolling.com/pinger/")
End With
For i As Integer = 0 To listToPing.Count - 1 Try pingURL = listToPing.Item(i).ToString Dim technoratiPing As HttpWebRequest = CType(WebRequest.Create(pingURL), HttpWebRequest) technoratiPing.Method = "POST" technoratiPing.ContentType = "text/xml" Dim streamPingRequest As Stream = CType(technoratiPing.GetRequestStream, Stream) Dim xmlPing As XmlTextWriter = New XmlTextWriter(streamPingRequest, System.Text.Encoding.UTF8) xmlPing.WriteStartDocument() xmlPing.WriteStartElement("methodCall") xmlPing.WriteElementString("methodName", "weblogUpdates.ping") xmlPing.WriteStartElement("params") xmlPing.WriteStartElement("param") xmlPing.WriteElementString("value", blogName) xmlPing.WriteEndElement() xmlPing.WriteStartElement("param") xmlPing.WriteElementString("value", blogURL) xmlPing.WriteEndElement() xmlPing.WriteEndElement() xmlPing.WriteEndElement() xmlPing.Close() Dim technoratiPingResponse As HttpWebResponse = CType(technoratiPing.GetResponse, HttpWebResponse) Dim streamPingResponse As StreamReader = New StreamReader(technoratiPingResponse.GetResponseStream) Dim strResult As String = streamPingResponse.ReadToEnd streamPingResponse.Close() technoratiPingResponse.Close() Catch ex As Exception 'Add code here to flag a service as broken End Try Next End Sub Make sure to set the blogURL and blogName variables to your blog information. With a little more code you could create a page to manage sites to ping. My idea for this page would be:
- Store the sites-to-ping in the database
- The table would have the fields SiteName, Active, and Failed
- In the Try Catch you could flag a site as failed if it fails. Set the Failed to false if it succeeds.
- On the Ping Site Management page display all the sites in a grid. Allow for add, editing, deleting.
I think you have the general idea. |