Calling URL through Proxy server(Address and Port)/Proxy Script

G

Guest

Hi All,
i m develpoing a .net Window application which has
4 texboxes(tbxURLmfor URL in URL Frame,tbxAddress for address in Proxy
server frame,tbxPort for port in proxy server frame,tbxProxyScript for proxy
script in proxy script frame) and a test button..The requirment is given below

STEP BY STEP GUIDE
1. Input the URL you want to test
2. Choose Proxy script/Proxy server with Address and Port Information/No proxy
3. Enter url to proxy script or info for proxy server in respective text box
4. Press test-button

---------------My Code is -------------------------------------------------
DateTime dt1 = DateTime.Now;
System.Net.HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create(tbxURL.Text.ToString());
//GetResponse for this request.
HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
DateTime dt2 = DateTime.Now;
lblTimeTaken.Text = Convert.ToString(dt2.Subtract(dt1));
--------------------------------------------------------------------
in this code , i m unable to set the value of proxy script textbox ,if any
or proxy server(Address and port) ,only thing which i do threough this code
is sending the url without any proxyscript ans proxy server(address and port
info) Can anybody tell me how can i do this thorugh the code....
...
i m working on window application as i need *.exe file rather than install
file ....


Thanks,
Deepak
 
G

Guest

Hi,

i tried with this code and it comiled and wokred fine but client
told me that when he traced the URL with his customized tool , he found that
my application is not using Proxy Script which i put in the texbox on the
form and i also found later that even code is working fine and application is
fine but we can not use URi class for Proxy Configuration Script.This is
wrong.This is nothing but we are using Address of URL which is diffrent from
ProxyScript.So this is not the solution.

so my question is how to do coding for calling URL when you want to access
that URL(mentioned in the textbox on the window form) with proxyscript.

if anybody have idea ,Please advice (for yours refrence i m giving u the
code which i put ,this code is filling my 2 requirments(URL alone,URL with
address and port) out of total3(URL alone,URL with address and port ,URL with
proxyscript only)

-----------------------------------------My Code is given
Below------------------------------------------------------------------------------------------------
private void Calc_Time_For_URL()

{

if(tbxURL.Text.StartsWith("https://"))

{

//Time of Request

DateTime dt1 = DateTime.Now;

try

{

System.Net.HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create(tbxURL.Text.ToString());

//Proxy Server(Address and Port)

if ((tbxAddress.Text.Length > 0) & (tbxPort.Text.Length >0))

{

myReq.Proxy = new WebProxy(tbxAddress.Text,Convert.ToInt16(tbxPort.Text));

}

//Proxy Script

if (tbxProxyScript.Text.Length > 0)

{

<-------------------THIS CODE IS WRONG, I NEED CODE FOR THIS SECTION

// Create a new Uri object.

Uri newUri=new Uri(tbxProxyScript.Text);

// Associate the newUri object to 'myProxy' object so that new myProxy
settings can be set.

myReq.Proxy = new WebProxy(newUri);

------------------------------------------------->

}


//GetResponse for this request.

HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();

//Time of Response

DateTime dt2 = DateTime.Now;

lblTimeTaken.Text = Convert.ToString(dt2.Subtract(dt1));

//}

}

catch(System.Exception ex)

{

//Time of Response

DateTime dt3 = DateTime.Now;

lblTimeTaken.Text = Convert.ToString(dt3.Subtract(dt1));

string message = "Make Sure URL is enterted with http://www or https://www
as prefix as per your need!!!\nError returned is :\n " + ex.Message;

string caption = "Error!!!";

DialogResult result;

MessageBoxButtons buttons = MessageBoxButtons.OK;

result = MessageBox.Show(message,caption,buttons);

}

}
 
G

Guest

Hi Vadym,
Proxy Script(TextBox):
http://www-proxy.ericsson.se:3132/accelerated_pac_base.pac
Url(TextBox):any URL which starts from https://

The below code is working fine for url (only URL,No ProxyServeri.e Address
and Port,no Proxy Script ), URL with ProxyServer(Address, Port) as given in
coding. but not for URL AND Proxy Script, That code needs to be changed.

Thanks for fast reply, if possibel u can reply me soon now as i m siting on
my workstation only wyaiting for preferct response.

Thanks,
Deepak
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)



Vadym Stetsyak said:
Hello, deepak!

What's proxy script?

d> Hi,

d> i tried with this code and it comiled and wokred fine but
d> client
d> told me that when he traced the URL with his customized tool , he
d> found that
d> my application is not using Proxy Script which i put in the texbox on
d> the
d> form and i also found later that even code is working fine and
d> application is
d> fine but we can not use URi class for Proxy Configuration Script.This
d> is
d> wrong.This is nothing but we are using Address of URL which is
d> diffrent from
d> ProxyScript.So this is not the solution.

d> so my question is how to do coding for calling URL when you want to
d> access
d> that URL(mentioned in the textbox on the window form) with
d> proxyscript.

d> if anybody have idea ,Please advice (for yours refrence i m giving u
d> the
d> code which i put ,this code is filling my 2 requirments(URL alone,URL
d> with
d> address and port) out of total3(URL alone,URL with address and port
d> ,URL with
d> proxyscript only)

d> -----------------------------------------My Code is given
d> Below-----------------------------------------------------------------
d> -------------------------------
d> private void Calc_Time_For_URL()

d> {

d> if(tbxURL.Text.StartsWith("https://"))

d> {

d> //Time of Request

d> DateTime dt1 = DateTime.Now;

d> try

d> {

d> System.Net.HttpWebRequest myReq =
d> (HttpWebRequest)WebRequest.Create(tbxURL.Text.ToString());

d> //Proxy Server(Address and Port)

d> if ((tbxAddress.Text.Length > 0) & (tbxPort.Text.Length >0))

d> {

d> myReq.Proxy = new
d> WebProxy(tbxAddress.Text,Convert.ToInt16(tbxPort.Text));

d> }

d> //Proxy Script

d> if (tbxProxyScript.Text.Length > 0)

d> {

d> <-------------------THIS CODE IS WRONG, I NEED CODE FOR THIS SECTION

d> // Create a new Uri object.

d> Uri newUri=new Uri(tbxProxyScript.Text);

d> // Associate the newUri object to 'myProxy' object so that new
d> myProxy
d> settings can be set.

d> myReq.Proxy = new WebProxy(newUri);

d> ------------------------------------------------->

d> }


d> //GetResponse for this request.

d> HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();

d> //Time of Response

d> DateTime dt2 = DateTime.Now;

d> lblTimeTaken.Text = Convert.ToString(dt2.Subtract(dt1));

d> //}

d> }

d> catch(System.Exception ex)

d> {

d> //Time of Response

d> DateTime dt3 = DateTime.Now;

d> lblTimeTaken.Text = Convert.ToString(dt3.Subtract(dt1));

d> string message = "Make Sure URL is enterted with http://www or
d> https://www
d> as prefix as per your need!!!\nError returned is :\n " + ex.Message;

d> string caption = "Error!!!";

d> DialogResult result;

d> MessageBoxButtons buttons = MessageBoxButtons.OK;

d> result = MessageBox.Show(message,caption,buttons);

d> }

d> }


d>
d> ----------------------------------------------------------------------
d> ----------------------------------------------------------------------
d> ----------------------

d> Thanks,
d> Deepak


d> "Vadym Stetsyak said:
Hello, deepak!
Here's the sample that uses Proxy server
( http://www.c-sharpcorner.com/Code/2004/Sept/DownloadUsingHTTP.asp )
( http://www.codeproject.com/cs/internet/httpwebrequest_response.asp )
d> Hi All,
d> i m develpoing a .net Window application which has
d> 4 texboxes(tbxURLmfor URL in URL Frame,tbxAddress for address in
d> Proxy
d> server frame,tbxPort for port in proxy server frame,tbxProxyScript
d> for proxy
d> script in proxy script frame) and a test button..The requirment is
d> given below
d> STEP BY STEP GUIDE
d> 1. Input the URL you want to test
d> 2. Choose Proxy script/Proxy server with Address and Port
d> Information/No proxy
d> 3. Enter url to proxy script or info for proxy server in respective
d> text box
d> 4. Press test-button
d> ---------------My Code is
d> -------------------------------------------------
d> DateTime dt1 = DateTime.Now;
d> System.Net.HttpWebRequest myReq =
d> (HttpWebRequest)WebRequest.Create(tbxURL.Text.ToString());
d> //GetResponse for this request.
d> HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
d> DateTime dt2 = DateTime.Now;
d> lblTimeTaken.Text = Convert.ToString(dt2.Subtract(dt1));
d>
--------------------------------------------------------------------
d> in this code , i m unable to set the value of proxy script textbox
d> ,if any
d> or proxy server(Address and port) ,only thing which i do threough
d> this code
d> is sending the url without any proxyscript ans proxy server(address
d> and port
d> info) Can anybody tell me how can i do this thorugh the code....
d> ..
d> i m working on window application as i need *.exe file rather than
d> install
d> file ....
d> Thanks,
d> Deepak
 
G

Guest

Should we have to call any API ..?Actually there is one exe file named
"proxycfg.exe" inside C:\windows\system32, and the application written is in
C# windows application...

Thanks,
Deepak
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)

deepak said:
Hi Vadym,
Proxy Script(TextBox):
http://www-proxy.ericsson.se:3132/accelerated_pac_base.pac
Url(TextBox):any URL which starts from https://

The below code is working fine for url (only URL,No ProxyServeri.e Address
and Port,no Proxy Script ), URL with ProxyServer(Address, Port) as given in
coding. but not for URL AND Proxy Script, That code needs to be changed.

Thanks for fast reply, if possibel u can reply me soon now as i m siting on
my workstation only wyaiting for preferct response.

Thanks,
Deepak
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

C# windows application 1
C# Windows Applications 1
Asp.net Important Topics. 0

Top