C# Windows Applications

G

Guest

Hi All,

I read article
(http://msdn.microsoft.com/msdnmag/issues/05/08/AutomaticProxyDetection/default.aspx). I need yours help. Please advise me



My Requirement is given below.



This is C# windows .net application(application as i need *.exe file
rather than install file ) which has 4 textboxes (tbxURL for 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 requirement 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


e.g.

A) Proxy Script (Textbox):
http://www-proxy.ericsson.se:3132/accelerated_pac_base.pac
B) URL (Textbox): any URL which starts from https://
C) Proxy Server (2 text box one for Address and one for Port):e.g.
10.187.1.20 and 8080

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


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 proxy
script.(which is filled in the textbox present on the window form. Please
advice (for yours reference, I am giving you the code which I put, this code
is filling my 2 requirements (URL alone), URL with address and port) out of
total3 (URL alone, URL with address and port, URL with proxy script 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 AND NOT
WORKING AND NEEDS TO BE CHANGED


// 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);

}



My Doubt is should we have to call any API..?Actually there is one exe file
named “proxycfg.exe" inside C:\windows\system32



Thanks,

Deepak

+919886735837

(e-mail address removed)

(e-mail address removed)

(e-mail address removed)
 
G

Guest

The framework doesnt do this for you automatically. You need to either write
the code to change the system settings to use the script you want, or use the
code from the sidebar to host the script yourself and call the functions in
it to get the proxy settings.
If you dont want to affect the system then the side bar is the only way to
go. Download the code and work with that stuff.

Ciaran O'Donnell
 

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

Top