[C#] Loading webpage through proxy

swordbeta

Newbie
Joined
Aug 10, 2009
Messages
12
Reaction score
91
I'm currently facing a problem, I'm a experienced PHP scripter and working on my C#, but I can't get this working.
My real question was, if there's a cUrl libary which is similar to PHP's cUrl libary and easy to use?
As I find it hard to use the WebRequest class (http://msdn.microsoft.com/en-us/library/debx8sh9.aspx)
I will also need to POST.
 
Last edited:
dude ur confusing me , in ur title you mention that u what to know Loading webpage through proxy and in the posy ur talking about webrequest class n post method , anyways if ur familer with winsock class in c# then u wont have any problem with both of them .
 
am a blackhat prograammer , n winsock makes ur bot like 50 faster then normal webbrowser class bot . so my advice is go for winsock
 
I created a class that uses httpwebrequest to do this. It currently only works with certain web proxies at the moment(php base64 encoded url). If you are interested PM me and ill send you the code and full explanation on how to use it.

I am also going to look into making it compatible with other proxy types and ip:port proxies and also adding winsock functionality.
 
Not familiar with PHP or Curl, but for Post. When i first learned C# i used this :

Code:
http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx

It certainly isnt perfect, and ive modified that code quite alot to allow for basic authentication and proxies. But its a good base.
 
dude ur confusing me , in ur title you mention that u what to know Loading webpage through proxy and in the posy ur talking about webrequest class n post method , anyways if ur familer with winsock class in c# then u wont have any problem with both of them .
Yes, I understand I am confusing you but I'm pretty sure my question was clear.
am a blackhat prograammer , n winsock makes ur bot like 50 faster then normal webbrowser class bot . so my advice is go for winsock
Ok, thank you, I will try that.
Not familiar with PHP or Curl, but for Post. When i first learned C# i used this :

Code:
http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx
It certainly isnt perfect, and ive modified that code quite alot to allow for basic authentication and proxies. But its a good base.
Looks like a good one, but I don't see proxy :(
 
Just use the webclient if you are looking for a simple way.
Here's a little snippet to get page using proxy.
Code:
Webclient wc = new Webclient();
 wc.proxy = "127.0.0.1:1337";
    string html = wc.downloadstring("[URL="http://www.google.com/"]http://www.google.com[/URL]");
 
Just use the webclient if you are looking for a simple way.
Here's a little snippet to get page using proxy.
Code:
Webclient wc = new Webclient();
 wc.proxy = "127.0.0.1:1337";
    string html = wc.downloadstring("[URL="http://www.google.com/"]http://www.google.com[/URL]");
Thank you, can I POST with that? Could you please give me a example?
And how do I go from string to System.Net.IWebProxy?
 
Last edited:
Sorry, must have pressed the button too much o.0
 
Last edited:
Sorry, must have pressed the button too much o.0
 
Last edited:
With mine you need to incorporate your own proxy into it. But it should be fairly easy. Implementing the timeouts etc may be a bit harder. But you will get there.

Just look at the MSDN library and you can pretty much copy and paste
 
Here is a little snippet of code to do a complete post request in c#

Code:
//Construct your request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("[URL]http://www.yoururl.com/[/URL]");
//If you want proxy support 
req.Proxy = new WebProxy("proxyurl", 8080);
req.ContentType = "application/x-www-form-urlencoded";
req.Accept = "image/gif, image/jpeg, */*";
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0;";
req.Referer = "[URL]http://www.refererurl.com/[/URL]";
req.Method = "POST";
//If you want to automagically follow 302 and 301 redirects set this to true
req.AllowAutoRedirect = false;
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("param1=value1&param2=value2");
req.ContentLength = bytes.Length;
//Make the real call
Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
//Never forget to close the stream
os.Close();
//Get the response
WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string response = sr.ReadToEnd().Trim();

Have fun
 
Sorry, didn't see the post above. The code I posted was practically identical =]
 
Last edited:
Thanks for the code, Ive been looking at various C# web browser controls but so far none seem to fit the bill....
 
Back
Top