azure - 我们如何在 services.AddAzureClients 上配置 HttpProxy
问题描述
我们的 .Net 5.0 aspnetcore 启动类中有以下代码
public void ConfigureServices(IServiceCollection services)
{
services.AddAzureClients(builder =>
{
// Add a storage account client
builder.AddBlobServiceClient(storageUrl);
// Use the environment credential by default
builder.UseCredential(new EnvironmentCredential());
});
services.AddControllers();
}
对于 HttpClient,我们可以使用以下代码配置 httpproxy,但是我们如何为 BlobServiceClient 实现相同的功能?
services.AddHttpClient("SampleClient", client =>
{
client.BaseAddress = new Uri("https://sample.client.url.com");
})
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
Proxy = new WebProxy("https://sample.proxy.url.com")
});
解决方案
The solution is to pass BlobClientOptions with the appropriate proxy URI specified, into the constructor of BlobServiceClient.
Checkout this sample code which shows how specify a proxy in a HttpClient
The HttpClient can be passed as a parameter when constructing a new HttpClientTransport, which can be set in the Transport property of BlobClientOption, which can then be passed into the constructor of BlobServiceClient.
推荐阅读
- javascript - 导航图标之间的间距相等
- c# - 无法解析对 Windows 运行时类型“Windows.Foundation.Metadata.PlatformAttribute”的依赖关系
- laravel - 试图在视图 sev.blade.php 中获取非对象的属性“数量”
- asp.net-mvc - 使用 MVC 创建可变长度的项目符号列表
- linux - cmake_minimum_required 行出错
- javascript - Javascript动态格式化带有项目符号的项目列表
- javascript - 无法设置未定义的属性“functionName”
- bash - 无法通过 bash 创建 IAM 访问密钥
- python - Conda 和 Anaconda 都在 Windows 机器上。Jupyter notebook 无法导入 Python 包
- java - 我的方法的 JUnit 测试