无法从Asp.Net的WebAPI操作方法连接到网站网址 [英] Not able to connect to website URLs from Asp.Net WebApi Action Methods

查看:84
本文介绍了无法从Asp.Net的WebAPI操作方法连接到网站网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接到使用Asp.Net的Web API项目的内部Web客户端的URL。我的目的是获取内容,并创建一个网站的缩略图。

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.

样code:

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

但是,这WebClient的客户对象抛出超时异常中的WebAPI的情况下,和控制台应用程序一样正常工作。

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

请帮助。

推荐答案

我找到了答案这里到底:的网络请求通过代理restSharp

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

添加

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

要我的web配置固定对我来说。

To my web config fixed it for me.

这篇关于无法从Asp.Net的WebAPI操作方法连接到网站网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆