Not able to connect to website URLs from Asp.Net WebApi Action Methods

帅比萌擦擦* 提交于 2020-01-21 09:10:09

问题


I am trying to connect to URL using WebClient inside Asp.Net Web Api project. My intention was to get the content and create a web site thumbnail.

Sample Code:

using (var client = new WebClient())
{
    var contents = client.DownloadString("http://www.google.com");
}

But this WebClient client object throws timeout exception in case of WebApi and same works fine for console application.

Kindly help.


回答1:


I found the answer here in the end: Web Request through Proxy using RestSharp

Adding:

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

To my web config fixed it for me.



来源:https://stackoverflow.com/questions/26845404/not-able-to-connect-to-website-urls-from-asp-net-webapi-action-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!