【问题标题】:ASP - running in localhost - unable to reach internetASP - 在本地主机中运行 - 无法访问互联网
【发布时间】:2011-01-12 05:40:51
【问题描述】:

我有一个 ASP MVC 控制器操作。 我正在尝试发出网络请求

public ActionResult Index()
{
   WebRequest request = HttpWebRequest.Create("http://www.example.com");
   WebResponse response = request.GetResponse();
   string str =  response.ToString();
}`

我得到一个“WebException 发生”远程名称无法解析:'www.example.com'

如果我启动 Fiddler,那么 webrequest 就可以了。

我尝试添加:

 <system.net>
 <defaultProxy>
   <proxy usesystemdefault ="True" bypassonlocal="True"  />
 </defaultProxy>

到 Web.config(有和没有 hte bypassonlocal),它仍然不起作用。

有什么建议吗?

【问题讨论】:

    标签: asp.net asp.net-mvc localhost web-scraping


    【解决方案1】:

    尝试明确指定代理服务器:

    <system.net>
        <defaultProxy>
            <proxy proxyaddress="http://proxy.yourcompany.com:80" />
        </defaultProxy>
    </system.net>
    

    您也可以通过编程方式设置代理:

    request.Proxy = new WebProxy("http://proxy.yourcompany.com:80", true);
    

    当您将usesystemdefault 设置为true 时,应用程序将使用Internet Options 对话框中定义的代理。当您在 IIS 中部署应用程序时,它通常在具有非常有限权限的 Network Service 帐户下执行,它甚至没有任何 GUI 会话,因此它无法推断代理服务器。

    【讨论】:

      猜你喜欢
      • 2015-02-12
      • 2017-11-22
      • 2017-03-04
      • 2021-10-09
      • 2018-10-10
      • 2018-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多