asp.net core defaultProxy

0

本文介绍了asp.net core defaultProxy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 net 4.5 中,我们正在使用这样的代理:

In net 4.5 we are working with proxy like this:

<system.net>
    <!-- -->
    <defaultProxy enabled="true" useDefaultCredentials="false">
        <proxy usesystemdefault="True" proxyaddress="http://192.168.1.1:8888" bypassonlocal="True" autoDetect="False" />
        <module type="CommonLibrary.Proxy.MyProxy, CommonLibrary, Version=1.0.0.0, Culture=neutral" />
    </defaultProxy>

    <settings>
        <httpWebRequest useUnsafeHeaderParsing="true" />
        <servicePointManager expect100Continue="false" />
    </settings>
</system.net>

但是在 asp.net core 或 test 中我们找不到像上面这样的解决方案有人可以帮我吗?

but in asp.net core or test we can't found a solution like the above Could someone please help me?

非常感谢您的帮助

谢谢,问候

推荐答案

虽然在可以使用 HttpClientHander 时手动设置代理工作,但默认所有请求都不需要代码,就像你可以在 .NET Framework 中做目前是不可能的.如果您使用的是不公开此功能的库,那就太可惜了.

Whilst manually setting the proxy works when it's possible to use a HttpClientHander, defaulting all requests to do so without code, like you could do in the .NET Framework is currently not possible. Which is bummer if you're using a library that doesn't expose this functionality.

谢天谢地,从 .NET Core 3.0 开始,只需设置环境变量就可以实现这一点(即,其行为与 Linux 一直有效):https://github.com/dotnet/corefx/issues/37187

Thankfully, from .NET Core 3.0, this will be possible simply by setting environment variables (i.e. behaves exactly as Linux has worked forever): https://github.com/dotnet/corefx/issues/37187

或者,https://github.com/dotnet/corefx/issues/36553 在 HttpClient 上添加了一个新的静态 DefaultWebProxy 属性,这将允许您通过代码完成相同的事情.这也将在 Core 3.0 中提供.

Alternatively, https://github.com/dotnet/corefx/issues/36553 added a new static DefaultWebProxy property on HttpClient that will allow you to accomplish the same thing via code. This will also be available in Core 3.0.

这篇关于asp.net core defaultProxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14