在开发环境中设置虚拟代理服务器

发布于 2024-12-10 11:20:24 字数 1466 浏览 0 评论 0原文

客户端站点上有一个代理服务器,所有外部请求都必须经过该代理服务器。我正在调用需要代理设置的外部 Web 服务。

我用来设置网络请求代理的代码如下所示。

我将如何在我的开发环境中设置测试代理服务器来验证我的代码是否有效?

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

There is a proxy server on the clients site that all external request must go through. I am calling an external web 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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心的憧憬 2024-12-17 11:20:24

您可以在开发环境中安装代理服务器并配置计算机,以便将服务部署在防火墙之外,并且您只需通过代理服务器连接到该服务。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文