Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using public proxy server in HTTP client

Tags:

c#

http

proxy

I am trying to use public proxy server (http://www.unblockwebnow.info/) to send HTTP request to destination site, say http://stackoverflow.com :)

My HTTP client has following architecture:

string url = "http://stackoverflow.com";
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.Method = "GET";

WebProxy myProxy = new WebProxy();
myProxy.Address = new Uri("http://www.unblockwebnow.info/");
HttpWRequest.Proxy = myProxy;

HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), encoding);
var rawHTML = sr.ReadToEnd();
sr.Close();

After executing the code for rawHTML I get "pageok -managed by puppet - hostingcms02 pageok"

If I comment out HttpWRequest.Proxy = myProxy; line, I get the site content.

like image 231
Norayr Amirkhanyan Avatar asked Dec 19 '12 17:12

Norayr Amirkhanyan


People also ask

Does HTTP support proxy server?

A proxy server lessens network traffic by rejecting unwanted requests, forwarding requests to balance and optimize server workload, and fulfilling requests by serving data from cache rather than unnecessarily contacting the true destination server. HTTP Server has proxy server capabilities built in.

What is proxy in HTTP client?

What Does HTTP Proxy Mean? An HTTP Proxy serves two intermediary roles as an HTTP Client and an HTTP Server for security, management, and caching functionality. The HTTP Proxy routes HTTP Client requests from a Web browser to the Internet, while supporting the caching of Internet data.

What is a HTTP proxy server used for?

A proxy server acts as a gateway between users and the internet and prevents access to anyone outside the network. Regular internet access via a web browser enables users to connect directly with websites. But a proxy acts as an intermediary, which communicates with webpages on users' behalf.


1 Answers

This seems to work, but not with your proxy (don't know port number for unblockwebnow.info). Added port number after ":" in URI

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://stackoverflow.com";
            HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
            HttpWRequest.Method = "GET";

            WebProxy myProxy = new WebProxy();

            //United States proxy, from http://www.hidemyass.com/proxy-list/
            myProxy.Address = new Uri("http://72.64.146.136:8080");
            HttpWRequest.Proxy = myProxy;

            HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
            StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), true);
            var rawHTML = sr.ReadToEnd();
            sr.Close();

            Console.Out.WriteLine(rawHTML);
            Console.ReadKey();
        }
    }
}
like image 58
a'' Avatar answered Oct 02 '22 15:10

a''