Click here to Skip to main content
13,353,322 members (59,616 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 29 Jan 2009

Technorati Ping Using C#

, 29 Jan 2009
Rate this:
Please Sign up or sign in to vote.
Source code to ping technorati for your blogs


Anyone that regularly reads or publishes blogs is probably familiar with the concept of pings. If you aren't familiar with the concept of ping, at least you've heard of it right?

A pingback (ping for short) is a method by which a blog authoring tool (such as WordPress sends notification to a "ping server" (such as Technorati) informing of new or updated content. The ping is sent via XML-RPC signal and allows the ping server to generate a list of blogs or sites that have new material. This way when surfers visit these sites they will get a listing of the blogs with the latest content.

Most of the existing blog-authoring tools have built-in pinging technology. If you want to create a blogging software then you will have to create the pinging function yourself. Using HTTPPost and C#, I have successfully created a method of doing this using a sample console application. This example uses Technorati but can just as easily be configured for any ping-service site that has an API.


Basic knowledge of C# and doing HttpPost is recommended.

Using the Code

Now that you understand what is ping and the purpose of it, let us see how we implement it in your code. Get the API of the source which you want to notify. Create the web request with the necessary details. For this example, I am adding the Content Length, Content Type. Once you assign all the details, just post and receive the response from the provider via HttpWebResponse.

How It Works ?

Three steps are included in completing the call and getting the response back:

  1. Initialize the request and set its properties.
  2. Send the request to the source using a stream.
  3. Receive and read the response.

Step 1: Initialize the Request and Set its Properties

  • Use the WebRequest.Create method to initialize new HttpWebRequest objects.
  • Now assign the property to "POST".
  • Assign other required parameters such as ContentType, ContentLength and any other additional parameters according to your API specifications.
HttpWebRequest webReq;
webReq = (HttpWebRequest)WebRequest.Create("");
webReq.Method = "POST";
webReq.ContentType = "text/xml";
webReq.ContentLength = strTechnoratiXML.Length;

Step 2: Send the Request to the Source Using a Stream

Once the initialisation of the request is completed, we need to send this data to the source. To do this, we need to use the "GetRequestStream" method which returns a stream. Then use Stream.write to send the request.

Stream streamRequest = webReq.GetRequestStream();
ASCIIEncoding ascii=new ASCIIEncoding();                
streamRequest.Write(ascii.GetBytes(strTechnoratiXML), 0, strTechnoratiXML.Length);

Step 3: Read the Response

Receive the response into HttpWebResponse using HttpWebRequest.GetResponse method. Now read the response into string with the help of StreamReader.

Once you are done with it, you must call either the Stream.Close or the HttpWebResponse.Close method to close the response and release the connection for reuse. It is not necessary to call both Stream.Close and HttpWebResponse.Close, but doing so does not cause an error.

HttpWebResponse webRes;
StreamReader srResponse;
webRes = (HttpWebResponse)webReq.GetResponse();
srResponse = new StreamReader(webRes.GetResponseStream(), Encoding.ASCII);
String strResponseText = srResponse.ReadToEnd();


After implementing this code in your site, you will have an edge over those without pingback capabilities by getting listed at the top-of-the-pile!

It is advised to use configuration file to customize the URL, description, and blog names so that you don't have to hardcode them into your function. Also, with a little bit of editing, you could loop through a list of services that allow you to programmatically send pingbacks.


This article has been amended to include more description of the article, which defines what ping is, where it is used and a simple explanation of how to post it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ravi Vooda
Software Developer (Senior) ValueLabs
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 2 Pin
Member 19923188-Nov-10 18:38
memberMember 19923188-Nov-10 18:38 
GeneralVS Pin
blackseth1-Feb-09 0:57
memberblackseth1-Feb-09 0:57 
GeneralMy vote of 1 Pin
Haluk_YILMAZ29-Jan-09 23:36
memberHaluk_YILMAZ29-Jan-09 23:36 
GeneralRe: My vote of 1 Pin
Ravi Vooda31-Jan-09 0:33
memberRavi Vooda31-Jan-09 0:33 
GeneralRe: My vote of 1 Pin
Haluk_YILMAZ31-Jan-09 13:01
memberHaluk_YILMAZ31-Jan-09 13:01 
GeneralAaaah... Pin
PIEBALDconsult29-Jan-09 11:55
memberPIEBALDconsult29-Jan-09 11:55 
GeneralRe: Aaaah... Pin
Ravi Vooda29-Jan-09 17:17
memberRavi Vooda29-Jan-09 17:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 29 Jan 2009
Article Copyright 2009 by Ravi Vooda
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid