问题
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