Home > C#, Useful Scripts > Free C# Web Reqest Class – LazyHTTP – cURL like Functionality

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

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
}
}
}
  1. No comments yet.
  1. No trackbacks yet.