Archive

Posts Tagged ‘C#’

Free C# Class – iliPing – Threadable, Fast, No External Classes Required

August 23rd, 2010 No comments

Before I give you another free C# class, I thought I may pass along a bit of a ProTip: it seems to me that the easiest money I make is from TextLinkAds. TLA capitalizes on the fact that spiders at least visit your site, even if real humans don’t. Join and give it a try.

This is a good class, and works well if you thread it. It works without using any other XML-RPC classes externally, and the only site it doesn’t work for me is sites that use nonstandard XML-RPC parameters like autopinger. I usually set it up to just go through a list of sites/blogs with their titles, and a list of XML-RPC ping service URI’s. I also thread this, and can ping quite quickly. This should be compatible with both .NET Framework, and my personal favorite, Mono (check out MonoDevelop sometime!).

Feel free to use this however and modify it…if you make any changes, please pay it forward and share them with everyone else so they can use the improvements too, since this is opensource.


/* iliPing - (C)2010 by ilikenwf, http://www.ilikenwf.com
* Feel free to use and/or modify this for any purpose...
* Please pay it forward and share any improvements you make
* Based on the XML-RPC pinging in C# class from
* http://mboffin.com/post.aspx?id=1613 modified and broken up */


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Serialization;
using System.Net;

namespace pinger
{
///

/// Sends an XML-RPC ping for the given blog, blog url, and ping service url.
///

public class pingRequestor : IDisposable
{
public string pingRequest(string blogname, string blogurl, string pingurl, bool verbosity,
int httpTO) {

string output = string.Empty;
try {
HttpWebRequest webreqPing = (HttpWebRequest)WebRequest.Create(pingurl);
webreqPing.UserAgent = "WordPress 3.0.1";
webreqPing.Timeout = httpTO;
webreqPing.Method = "POST";
webreqPing.ContentType = "text/xml";

// Get the stream for the web request
Stream streamPingRequest = (Stream)webreqPing.GetRequestStream();

// Create an XML text writer that writes to the web request's stream
XmlTextWriter xmlPing = new XmlTextWriter(streamPingRequest, Encoding.UTF8);

// Build the ping, using the BlogName and BlogUrl
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();

// Close the XML text writer, flusing the XML to the stream
xmlPing.Close();

// Send the request and store the response, then get the response's stream
HttpWebResponse webrespPing = (HttpWebResponse)webreqPing.GetResponse();

StreamReader streamPingResponse = new StreamReader(
webrespPing.GetResponseStream());
XmlDocument response = new XmlDocument();

// Store the result in an XmlDocument for parsing if verbosity is off
if (verbosity == false) {
response.LoadXml(streamPingResponse.ReadToEnd());
} else {
output = streamPingResponse.ReadToEnd();
}

// Close the response stream and the response itself
streamPingResponse.Close();
webrespPing.Close();

if (verbosity == false)
{
// Check the response to determine success or failure
XmlElement flerror = (XmlElement)response.SelectSingleNode("//boolean");
switch (flerror.InnerText)
{
case "0":
output = "[Success] ";
break;
case "false":
output = "[Success] ";
break;
default:
output = "[Failure] ";
break;
}
}
} catch {
// Timeout here is somewhat generic and nonspecific
output = "[Timeout] ";
}
// Return the result
return output;
}

public void Dispose() {
}

}
}

Free C# Web Reqest Class – LazyHTTP – cURL like Functionality

December 29th, 2009 No comments

Before I give you the free C# class, I thought I may pass along a bit of a ProTip: it seems to me that the laziest source of income I get is from TextLinkAds. This is just a little protip, but you should really join TLA and slap their plugin onto all of your accepted blogs. You will make money…without doing anything. I’m sick and tired of hearing people complain their sites are indexed but not making money. TLA capitalizes on the fact that spiders at least visit your site, even if real humans don’t. Join and give it a try.

See the class below. If you can’t understand how to use it, you may want to brush up on C# … or get a book or something. Here is LazyHTTP (special thanks to nuls on the Syndk8 Blackhat SEO Forums for cleaning this up):


/* LazyHTTP Lazy Request Class. (c) 2009 by ilikenwf http://www.ilikenwf.com
* Special thanks to nuls of the syndk8 forums at http://forum.syndk8.net
* feel free to copy, modify, share, and distribute as you wish,
* and to include this in any projects you may have, commercial or not.
* please just leave the credits line up above.
* In other words, consider this licensed under the GNU Public License */


using System;
using System.Net;
using System.IO;
using System.Text;

namespace LazyHTTP
{
public class LazyClient : WebClient, IDisposable
{
public new string DownloadString(string address)
{
string output = String.Empty;

try {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
request.UserAgent = @"YOUR USERAGENT STRING HERE";
request.KeepAlive = false;
request.Timeout = 15 * 1000;

HttpWebResponse res = (HttpWebResponse) request.GetResponse();

using (StreamReader streamReader = new StreamReader(res.GetResponseStream())) {
output = streamReader.ReadToEnd();
}
} catch {
// Error Hiding - Weeee!
}
return output;
}

public void PostAction(string address, string postString)
{
try {
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(address);
req.Timeout = 3000;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ServicePoint.Expect100Continue = false;
byte[] postBytes = new UTF8Encoding().GetBytes(postString);
req.ContentLength = postBytes.Length;
using (Stream stream = req.GetRequestStream()) {
stream.Write(postBytes, 0, postBytes.Length);
stream.Close();
}
req.GetResponse().Close();
} catch {
// Error Hiding - Weeee!
}
}

public void Dispose()
{
// Needed for IDisposable Interface
}
}
}