Enjoy.Code:using System;
using System.Text;
using System.Net;
using System.IO;
using System.Collections;
using System.Diagnostics;
using System.Collections.Generic;
public class HTTPWrapper
{
private CookieContainer Cookies = new CookieContainer();
private Hashtable rawCookies = new Hashtable();
private String Proxy = String.Empty;
private String User_Agent = String.Empty;
public String post(String URL)
{
return post(URL, "", "");
}
public String post(String URL, String Data)
{
return post(URL, Data, "");
}
public String post(String URL, String Data, String Referer)
{
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
Request.Method = "POST";
Request.ContentType = "application/x-www-form-urlencoded";
Request.Referer = Referer;
Request.ContentLength = Data.Length;
Request.CookieContainer = Cookies;
try
{
Request.UserAgent = (User_Agent != String.Empty) ? User_Agent : null;
}
finally
{
Request.UserAgent = null;
}
try
{
Request.Proxy = (Proxy != String.Empty) ? new WebProxy(Proxy) : null;
}
finally
{
Request.Proxy = null;
}
try
{
Stream rs = Request.GetRequestStream();
byte[] Bytes = Encoding.ASCII.GetBytes(Data);
rs.Write(Bytes, 0, Bytes.Length);
rs.Close();
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
for (int i = 0; i < Response.Cookies.Count; i++)
{
Cookies.Add(Response.Cookies[i]);
if (rawCookies.ContainsKey(Response.Cookies[i].Name)) rawCookies.Remove(Response.Cookies[i].Name);
rawCookies.Add(Response.Cookies[i].Name, Response.Cookies[i].Value);
}
return (new StreamReader(Response.GetResponseStream())).ReadToEnd();
}
catch (Exception ex)
{
Debug.Write(ex.Message);
return String.Empty;
}
}
public String get(String URL)
{
return get(URL, "");
}
public String get(String URL, String Referer)
{
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
Request.Method = "GET";
Request.Referer = Referer;
Request.CookieContainer = Cookies;
try
{
Request.UserAgent = (User_Agent != String.Empty) ? User_Agent : null;
}
finally
{
Request.UserAgent = null;
}
try
{
Request.Proxy = (Proxy != String.Empty) ? new WebProxy(Proxy) : null;
}
finally
{
Request.Proxy = null;
}
try
{
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
for (int i = 0; i < Response.Cookies.Count; i++)
{
Cookies.Add(Response.Cookies[i]);
if (rawCookies.ContainsKey(Response.Cookies[i].Name)) rawCookies.Remove(Response.Cookies[i].Name);
rawCookies.Add(Response.Cookies[i].Name, Response.Cookies[i].Value);
}
return (new StreamReader(Response.GetResponseStream())).ReadToEnd();
}
catch (Exception ex)
{
Debug.Write(ex.Message);
return String.Empty;
}
}
public Stream get_stream(String URL)
{
return get_stream(URL, "");
}
public Stream get_stream(String URL, String Referer)
{
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(URL);
Request.Method = "GET";
Request.Referer = Referer;
Request.CookieContainer = Cookies;
try
{
Request.UserAgent = (User_Agent != String.Empty) ? User_Agent : null;
}
finally
{
Request.UserAgent = null;
}
try
{
Request.Proxy = (Proxy != String.Empty) ? new WebProxy(Proxy) : null;
}
finally
{
Request.Proxy = null;
}
try
{
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
for (int i = 0; i < Response.Cookies.Count; i++)
{
Cookies.Add(Response.Cookies[i]);
if (rawCookies.ContainsKey(Response.Cookies[i].Name)) rawCookies.Remove(Response.Cookies[i].Name);
rawCookies.Add(Response.Cookies[i].Name, Response.Cookies[i].Value);
}
return Response.GetResponseStream();
}
catch (Exception ex)
{
Debug.Write(ex.Message);
return null;
}
}
public CookieContainer cookies
{
get {
return Cookies;
}
set {
this.Cookies = value;
}
}
public String cookie(String Name)
{
return ((rawCookies.ContainsKey(Name)) ? (String)rawCookies[Name] : String.Empty);
}
public String proxy
{
get
{
return Proxy;
}
set
{
this.Proxy = value;
}
}
public String user_agent
{
get
{
return User_Agent;
}
set
{
this.User_Agent = value;
}
}
public String between(String Input, String Start, String End)
{
return between(Input, Start, End, 0);
}
public String between(String Input, String Start, String End, Int32 Offset)
{
if (Input.Length > 0 && Start.Length > 0 && End.Length > 0 && Offset < Input.Length)
{
Int32 StartPos = (Input.IndexOf(Start, Offset) + Start.Length);
if ((StartPos - Start.Length) > -1 && Input.Length >= StartPos)
{
Int32 Length = (Input.IndexOf(End, StartPos) - StartPos);
if (Length > -1)
{
return Input.Substring(StartPos, Length);
}
}
}
return String.Empty;
}
public List<String> all_between(String Input, String Start, String End)
{
List<String> Values = new List<String>();
Int32 Offset = 0;
while (true)
{
if (Input.Length > 0 && Start.Length > 0 && End.Length > 0 && Offset < Input.Length)
{
Int32 StartPos = (Input.IndexOf(Start, Offset) + Start.Length);
if ((StartPos - Start.Length) > -1 && Input.Length >= StartPos)
{
Int32 Length = (Input.IndexOf(End, StartPos) - StartPos);
if (Length > -1)
{
Values.Add(Input.Substring(StartPos, Length));
Offset = StartPos + Length;
continue;
}
}
}
break;
}
return Values;
}
}