Tim Hastings - NonHostile (because there's no need)

Weblog and collection of geeky articles.

  Home :: Who? :: Contact :: Links :: Subscribe subscribe
Happy Birthday Mum!The Christening of Christopher Mark and Daniel Albert HastingsThe Garden Project


This code snippet will probably be of interest to about 3 4 5 people in the entire world (counting myself).
If you have a home grown weblog (like this one) implemented using classic ASP and you want to ping Technorati with updates, then here's the snippet for you.

Incidentally, this is my Technorati Profile (claim code: Technorati Profile)

Technorati have an XML RPC that allows you to notify their backend systems that your weblog has been updated.
They then send one of their bots to read your website to update their databases.

For Technorati's page about doing your own pinging, visit: http://www.technorati.com/developers/ping/
You contact the RPC's endpoint via HTTP at the URL: http://rpc.technorati.com/rpc/ping

To send data, you must perform a HTTP Post containing XML that looks like this:
    <?xml version="1.0"?>
    <methodCall>
      <methodName>weblogUpdates.ping</methodName>
      <params>
        <param>
          <value>YOUR WEBLOG NAME HERE</value>
        </param>
        <param>
          <value>http://www.YOURWEBLOGURL.com/</value>
        </param>
      </params>
    </methodCall>
This ASP code snippet defines a function that performs the ping and calls it.
The routine is light on error handling, but it does the business.
    option explicit
    
    ' ensure that this script runs every time
    Response.Expires = -1
    Response.CacheControl = "private"
    
    ' do the ping, and keep the response
    dim strData
    strData = PingTechnorati("My Weblog Title", "http://www.myweblog.com/")
    
    ' output the response (encoded as HTML to humans can see the XML)
    Response.Write Server.HTMLEncode(strData)
    
    ' a reusable pinging function
    function PingTechnorati(byval strBlogName, byval strBlogUrl)
    
        dim objXml, objHttp, strData, strReturn
    
        ' build ping XMLRPC call
        strData = "<?xml version=""1.0""?>"
        strData = strData & "<methodCall>"
        strData = strData & "<methodName>weblogUpdates.ping</methodName>"
        strData = strData & "<params>"
        strData = strData & "<param>"
        strData = strData & "<value>" & XmlSafe(strBlogName) & "</value>"
        strData = strData & "</param>"
        strData = strData & "<param>"
        strData = strData & "<value>" & XmlSafe(strBlogUrl) & "</value>"
        strData = strData & "</param>"
        strData = strData & "</params>"
        strData = strData & "</methodCall>"
    
        ' post to technorati XMLRPC ping URL
        set objHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
        objHttp.open "POST", "http://rpc.technorati.com/rpc/ping", false
        objHttp.setRequestHeader "Content-Type", "text/xml"
        objHttp.setRequestHeader "Content-Length", len(strData)
        objHttp.Send strData
    
        ' check response
        if (objHttp.status = 200) then
            strReturn = objHttp.responseText
        end if
    
        ' thanks, bye
        set objHttp = nothing
        
        ' passback
        PingTechnorati = strReturn
    
    end function
    
    ' escape special XML characters 
    function XmlSafe(byval strData) 
        strData = replace(strData, "&", "&amp;")
        strData = replace(strData, "'", "&apos;")
        strData = replace(strData, """", "&quot;")
        strData = replace(strData, "<", "&lt;")
        strData = replace(strData, ">", "&gt;")
        XmlSafe = strData
    end function
Choking Hazard: Because the input parameters to the function are combined to form an XML string it would be possible to create invalid XML, the XmlSafe function makes sure that the basic special XML characters < > & ' and " are escaped in the proper XML way.



3 comments, Web, Thursday, July 28, 2005 23:22

Timeline Navigation for Web posts
Privacy Risk With Internet Explorer (made 31 weeks later)
ASP: Pinging Technorati from the Server Side using XMLRPC and Classic ASP (this post, made Thursday, July 28, 2005 23:22)
Software Development Jobs in Blackpool and Lancashire (demonstrating syndication at work) (made 1 week earlier)


Comments
This is wonderful. For a long time i was looking for such a code. Now your code interests 4th person. :)

Posted by: Chan on Tuesday, January 3, 2006 17:30
Thanks Chan, I'm glad you found it useful!

Posted by: Tim on Tuesday, January 3, 2006 20:14
Thank you! I also found this very useful.

Posted by: Astralis on Saturday, February 11, 2006 02:58

Post a Comment
Name:  Home page and email address are optional.
  Email addresses will not be displayed or spammed!
Remember these details
Email:
Home Page:
Comment:
Comments cannot contain HTML, URLs will be formatted into hyperlinks.
I reserve the right to remove any comments for any reason.