1

I have an application in C# which uses a service reference to send SMS through a web service. The user's internet connection needs to pass through a proxy server in order to reach the world.

So my question is how to tell .NET to call web service through the proxy? Or how to set proxy settings for internet connection of my application just like what you can do in YMahoo Messenger?

Also I want to let user to choose proxy settings.

2 Answers 2

6

I believe what you are looking for is defaultProxy in your config file.

Here's an example from the link:

<configuration>
  <system.net>
    <defaultProxy>
      <proxy
        usesystemdefault="true"
        proxyaddress="http://192.168.1.10:3128"
        bypassonlocal="true"
      />
      <bypasslist>
        <add address="[a-z]+\.contoso\.com" />
      </bypasslist>
    </defaultProxy>
  </system.net>
</configuration>
Sign up to request clarification or add additional context in comments.

2 Comments

Where should I set it in VS 2010? How can I modify it programmatically?
in the config file. see the link provided for more information.
3

Please try below code hope this will help you

tring targetUrl = "http://www.google.com";
string proxyUrlFormat = "http://zend2.com/bro.php?u={0}&b=12&f=norefer";
string actualUrl = string.Format(proxyUrlFormat, HttpUtility.UrlEncode(targetUrl));

// Do something with the proxy-ed url
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(actualUrl));
HttpWebResponse resp = req.GetResponse();

string content = null;
using(StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
    content = sr.ReadToEnd();
}

Console.WriteLine(content);

2 Comments

I am not making the request in my own code. The code fro request is generated by the service reference addition. Additionally application is acapable of auto-update so I want to enable for whole the application. Most likely using System.Net.GlobalProxySelection class is a solution but is obsolote!
I am now using GlobalProxySelection class to apply user settings. However the user is siting behind a domain controller and needs to set username and pasword for proxy setings in order to access the Internet. How do I set username and password?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.