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; } }
Results 1 to 14 of 14
Thread: C# HTTPWrappers [Private]
- 18 Jul. 2010 10:17am #1
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 0.00
C# HTTPWrappers [Private]
- 18 Jul. 2010 08:27pm #2
- 19 Jul. 2010 12:17am #3
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 0.00
- 19 Jul. 2010 03:45am #4
I would figure that the Request class would handle that.
- 19 Jul. 2010 04:00am #5
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 0.00
- 29 Jul. 2010 10:20am #6
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 0.00
- 29 Jul. 2010 08:19pm #7
- 29 Jul. 2010 11:59pm #8
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 0.00
- 16 Sep. 2010 01:28am #9
- 16 Sep. 2010 09:46am #10
- 16 Sep. 2010 01:33pm #11
- 17 Sep. 2010 05:07am #12
Well I hate Vb.net and I love C# and PHP and of course my school is so gay that they decided to say, "We aren't allowed to host PHP files on our server." so I'm stuck with C# and I wanted to make a program (just for me) to auto get my grades when I login on my school computer.
- 17 Sep. 2010 01:48pm #13
- 08 Oct. 2010 09:09pm #14Code:
http://www.hackforums.net/showthread.php?tid=687178
Bman will never learn.