tags:

views:

36

answers:

3

hi
I want to implement program by c# application. first of all I need web request to a remote server and set proxy and view sourcecode of that page.

How I can write codes is there any code?

+2  A: 

You may want to have a look at this.

Simon Linder
it is give me error. I set my proxy https://ems28.your-freedom.de port 443but it said it cant resolve https
kamiar3001
At the end of the link I posted is an example for HTTPS. According to this your proxy should be instanciated with WebProxy myProxy = new WebProxy("https://ems28.your-freedom.de", 443); and not with WebProxy myProxy = new WebProxy("https://ems28.your-freedom.de:8080", 443);
Simon Linder
I do it but it gives me something else : The remote server returned an error: (403) Forbidden.
kamiar3001
Obviously you are either have the wrong credentials, or you are missing credentials for the WebRequest itself, meaning: are you missing something like req.Credentials = new NetworkCredentials("abc", "xyz");?
Simon Linder
I set them correctly but I dont know about domain network you know that new NetworkCredentials("user", "pass", Domain) is that important
kamiar3001
Domain is only important if your username that you use for authentification is in a specified domain, like myUsername@specifiedDomain.
Simon Linder
You could also try to inspect your request with WireShark and/or Fiddler to find out what is happening (just google it).
Simon Linder
A: 
string addr = textBox1.Text;
        string result = "";

        Uri uri = WebRequest.DefaultWebProxy.GetProxy(new Uri(addr));

        WebProxy myProxy = new WebProxy("ems28.your-freedom.de", 443);
        myProxy.Credentials = new NetworkCredential("user", "pass");
        myProxy.BypassProxyOnLocal=true;

        try{
        WebRequest req = WebRequest.Create(addr);
        req.Proxy = myProxy;

        HttpWebResponse response = (HttpWebResponse)req.GetResponse(); System.IO.Stream stream = response.GetResponseStream();
        System.Text.Encoding ec = System.Text.Encoding.GetEncoding("utf-8");
        System.IO.StreamReader reader = new System.IO.StreamReader(stream, ec);
        char [] chars = new Char[256];
        int count = reader.Read(chars, 0, 256);
        while(count > 0)
        {
        string str = new String(chars, 0, 256);
        result = result + str;
        count = reader.Read(chars, 0, 256);
        }
        response.Close();
        stream.Close();
        reader.Close();
        }
        catch(Exception exp)
        {
        string str = exp.Message;
        }
        MessageBox.Show(result);

        webBrowser1.Url = uri;
        webBrowser1.GoForward();
kamiar3001
it gives me it could not be resolve https
kamiar3001
A: 

If you are developing ASP.NET websites you can also set the proxy globally for all web requests in the web.config like so:

<configuration>
   <system.net>
      <defaultProxy>
         <proxy
            usesystemdefault = "false"
            proxyaddress="http://proxyserver"
            bypassonlocal="true"
         />
      </defaultProxy>
   </system.net>
</configuration>

See http://support.microsoft.com/default.aspx?scid=kb;en-us;318140

Dan Diplo