简体   繁体   English

无法从Asp.Net MVC连接到远程服务器

[英]Unable to connect to the remote server from Asp.Net MVC

I'm trying to get the data from external website using webclient inside my Asp.Net MVC application. 我正在尝试使用Asp.Net MVC应用程序内的webclient从外部网站获取数据。 I'm using the following code to get the text. 我正在使用以下代码来获取文本。

using (WebClient client = new WebClient()) 
{
      string htmlCode = client.DownloadString("http://google.com");    
}

But, I'm getting The operation has timed out exception. 但是,我收到操作已超时异常。

If I use the same code within WPF App or WinForms App, its working perfectly. 如果我在WPF应用程序或WinForms应用程序中使用相同的代码,则可以正常工作。 Is there any configuration I'm missing in my Web Application? Web应用程序中是否缺少任何配置?

note: I have tried using WebRequest class and no success with that too. 注意:我尝试使用WebRequest类,但也没有成功。

Old question but the answer for future generations might be that you need to use a web proxy. 旧的问题,但对子孙后代的答案可能是您需要使用Web代理。 Something like this: 像这样:

WebClient client = new WebClient();
WebProxy proxyObject = new WebProxy("http://yourproxy.something:1234/", true);
client.Proxy = proxyObject;

We too got the same error. 我们也有同样的错误。 After adding the below code in Web.Confing issue has been resolved for us. 在Web.Confing中添加以下代码后,我们已经解决了问题。

  <system.net>
    <defaultProxy useDefaultCredentials="true" >
    </defaultProxy>
  </system.net>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM