c# - 无法从 IIS 中托管的网站发出外部请求
问题描述
我有一个 asp.net 核心网站,它从操作方法内部进行外部 HTTP 调用
public class MyController : Controller
{
public IActionResult GetData()
{
try
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://test.api.somewebsite/data");
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
var resp = webRequest.GetResponse();
var stream = resp.GetResponseStream();
byte[] bytes = new byte[10000];
stream.Read(bytes, 0, bytes.Length);
return Ok(bytes);
}
catch(Exception ex)
{
log(ex);
return null;
}
}
}
当我在 IIS-Express 或作为独立控制台 ASP.NET Core 应用程序运行时,一切正常(我从外部网站获得 200 状态)。
当我在本地 IIS(同一台计算机)中托管网站时,出现此异常
System.Net.WebException:发送请求时出错。无法建立与服务器的连接
任何人都知道为什么我无法从 IIS 内部访问该 url?
谢谢
更新实际上我不能从 IIS 内部进行 HTTP 或 HTTPS 调用。
解决方案
推荐阅读
- python - Python asyncio await-for timeout 不适用于无限任务
- python - QWidget 不接受大于大约 23000 的 setFixedSize 值
- ios - objective-c : 2 个 viewControllers 之间的自定义 segue 转换
- laravel - 使用 Guzzle 客户端获取 API 数据
- angular - Angular 10:下一次调用后订阅 observable 不会触发
- laravel - 尽管获取视图未找到错误,但视图存在
- python-3.x - Pymongo 使用附加列表值更新集合
- r - R中的双向条形图
- docker - Mac 的 Docker 桌面:绑定到 tcp 端口
- linux - 在 Docker 构建中创建文件