C# 使用代理服务器上载Azure存储客户端库
我正在使用azure存储客户端将一些文件上载到azure blob存储。此上载是从存储在本地计算机中的C# 使用代理服务器上载Azure存储客户端库,c#,azure,proxy,azure-storage-blobs,C#,Azure,Proxy,Azure Storage Blobs,我正在使用azure存储客户端将一些文件上载到azure blob存储。此上载是从存储在本地计算机中的dll文件进行的。下面是我正在使用的代码 public bool UploadBlob(byte[] fileContent, CloudStorageAccount account, string containerName, string blobName) { try { CloudBlobClient blobclien
dll
文件进行的。下面是我正在使用的代码
public bool UploadBlob(byte[] fileContent, CloudStorageAccount account, string containerName, string blobName)
{
try
{
CloudBlobClient blobclient = account.CreateCloudBlobClient();
CloudBlobContainer container = blobclient.GetContainerReference(containerName);
container.CreateIfNotExist();
CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
HashSet<string> blocklist = new HashSet<string>();
foreach (FileBlock block in GetFileBlocks(fileContent))
{
if (ScanTool.mIsThreadStop)
return false;
ScanTool.mDocumentUploadedSize += block.Content.Length;
blob.PutBlock(
block.Id,
new MemoryStream(block.Content, true),
null
);
blocklist.Add(block.Id);
}
blob.PutBlockList(blocklist);
blob.FetchAttributes();
return blob.Properties.Length == fileContent.Length;
}
catch (Exception e) {
Log.WriteErrorLog(e, "UploadBlob at AzureBlobUtilCS");
throw new System.Net.WebException();
}
}
这个问题是在我的一个客户站点中遇到的,他说他们的本地网络中有一个代理。代理名称为bluecoat Proxy SG 900
如何摆脱此问题?我遇到了类似的问题,不仅在Azure存储中,而且在整个网站上 为了禁用Azure存储使用的默认代理,它恰好是
HttpClient
类使用的默认代理,我通过添加defaultProxy
元素更改了Web.config
:
<configuration>
<system.net>
<defaultProxy enabled="false"></defaultProxy>
</system.net>
</configuration>
如果您必须配置默认代理,而不是禁用它,您也可以在同一元素中进行配置,根据文档:您可以尝试在app/web config文件中设置代理设置:。请按照上面Gaurav的说明操作。:)@肇星路有没有办法使用azure存储客户端库对代理进行身份验证?我认为该设置不在azure存储客户端库级别。您应该在defaultProxy中全局设置,相关问题:,
<configuration>
<system.net>
<defaultProxy enabled="false"></defaultProxy>
</system.net>
</configuration>