开发者

Set up dummy proxy server on a dev environment

开发者 https://www.devze.com 2023-04-13 07:22 出处:网络
There is a proxy server on the clients site that all external request must go through. I am calling an external w开发者_JAVA技巧eb service that needs the proxy settings.

There is a proxy server on the clients site that all external request must go through. I am calling an external w开发者_JAVA技巧eb service that needs the proxy settings.

The code I am using to set up the proxy for the web request can be seen below.

How would I go about setting up a test proxy server on my developer environment to verify that my code works?

            string url = String.Format("http://currencyconverter.kowabunga.net/converter.asmx/GetConversionAmount?CurrencyFrom={0}&CurrencyTo={1}&RateDate={2}&Amount={3}", CurrencyFrom.Text, CurrencyTo.Text, formattedDate, amount);

            WebRequest request = WebRequest.Create(url);

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["proxyLogin"]))
            {
                WebProxy proxy = new WebProxy();

                string proxyUrl = ConfigurationManager.AppSettings["proxyUrl"];

                if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["proxyPort"]))
                {
                    proxyUrl += ":" +ConfigurationManager.AppSettings["proxyPort"];
                }

                // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
                proxy.Address = new Uri(proxyUrl);
                // Create a NetworkCredential object and associate it with the 
                // Proxy property of request object.
                proxy.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["proxyLogin"], ConfigurationManager.AppSettings["proxyPassword"]);
                request.Proxy = proxy;
            }

            WebResponse response = request.GetResponse();


You can install a proxy server in your development environment and configure the machines in such a way that the service is deployed beyond the firewall and you need to connect to the service through the proxy server only.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号