System.Net.IWebProxy(来自 System.Net.Primitives,DNX Core)的可用实现是什么?根据应用需求,dnxcore50 中可以使用唯一的框架,那么包含代理实现的正确 NuGet 包是什么?
解决此类问题的正确方法是什么?相关功能似乎被分成了几十个包。
尽管名称如此,IWebProxy 实现实际上并不需要实现任何代理,它只是提供有关代理的信息。因此,您可以创建自己的实现:
public class MyProxy : IWebProxy
{
public Uri GetProxy(Uri destination)
{
return new Uri("http://localhost:8888");
}
public bool IsBypassed(Uri host)
{
return false;
}
public ICredentials Credentials { get; set; }
}
命名空间中有一个可以使用的WebProxy
类System.Net
(来源here )。
确保您的 project.json 文件在“依赖项”下有这两行
"frameworks": {
"dotnet5.4": {
"dependencies": {
"Microsoft.Net.Http": "2.2.29",
"System.Net.Primitives": "4.0.11-beta-23516"
}
}
}