2010-10-22 142 views
5

我的“LocalClient”应用程序位于HTTP代理服务器(ISA)后面的公司LAN中。我做的第一个Azure API调用 - CloudQueue.CreateIfNotExist() - 会导致一个异常:(407)需要代理验证。我尝试以下操作:通过代理服务器连接到Azure存储帐户

按照MSDN,HTTP代理服务器,可以在连接字符串中只在开发存储的情况下规定(见http://msdn.microsoft.com/en-us/library/ee758697.aspx):
UseDevelopmentStorage=true;DevelopmentStorageProxyUri= http://myProxyUri

有什么方法来连接到Azure存储通代理服务器?

回答

3

定制代理解决方案(我在原始问题中提到的第三件事)完美地工作。我之前所做的错误不是根据需要将<configSections>元素放置在app.config的<configuration>开头。在这样做,给定的代理解决方案here解决了我的问题。

7

我确实发现自定义代理解决方案不是必需的。

加入以下的app.config(只是</configuration>前)为我做的伎俩:

<system.net> 
<defaultProxy enabled="true" useDefaultCredentials="true"> 
<proxy usesystemdefault="true" /> 
</defaultProxy> 
</system.net> 
+0

是的,这应该在大多数情况下工作,我想。我也尝试过。但在我的情况下,代理服务器(Squid)预计没有域的用户名。发送给它的登录用户名(按照useDefaultCredentials设置)为 \ 格式。所以它不会进行身份验证。 – amolbk 2013-07-03 06:43:43

+0

谢谢,你的解决方案帮助我! – codebot 2014-09-02 08:21:28

+0

这也适用于我(当我试图在桌子上进行任何操作时,我的应用程序被挂起)。 – Adam 2016-06-02 10:19:15

0

若要通过代理,那么请使用如下,它按预期工作,并同一直测试。

public class AzureUpload { 

    // Define the connection-string with your values 
    /*public static final String storageConnectionString = 
     "DefaultEndpointsProtocol=http;" + 
     "AccountName=your_storage_account;" + 
     "AccountKey=your_storage_account_key";*/ 
    public static final String storageConnectionString = 
      "DefaultEndpointsProtocol=http;" + 
      "AccountName=test2rdrhgf62;" + 
      "AccountKey=1gy3lpE7Du1j5ljKiupjhgjghjcbfgTGhbntjnRfr9Yi6GUQqVMQqGxd7/YThisv/OVVLfIOv9kQ=="; 

    // Define the path to a local file. 
    static final String filePath = "D:\\Project\\Supporting Files\\Jar's\\Azure\\azure-storage-1.2.0.jar"; 
    static final String file_Path = "D:\\Project\\Healthcare\\Azcopy_To_Azure\\data"; 

    public static void main(String[] args) { 
     try 
     { 
      // Retrieve storage account from connection-string. 
      //String storageConnectionString = RoleEnvironment.getConfigurationSettings().get("StorageConnectionString"); 
      //Proxy httpProxy = new Proxy(Proxy.Type.HTTP,new InetSocketAddress("132.186.192.234",8080)); 
      System.setProperty("http.proxyHost", "102.122.15.234"); 
      System.setProperty("http.proxyPort", "80"); 
      System.setProperty("https.proxyUser", "ad001\\empid001"); 
      System.setProperty("https.proxyPassword", "pass!1"); 
      // Retrieve storage account from connection-string. 
      CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); 

      // Create the blob client. 
      CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); 


      // Get a reference to a container. 
      // The container name must be lower case 
      CloudBlobContainer container = blobClient.getContainerReference("rpmsdatafromhospital"); 

      // Create the container if it does not exist. 
      container.createIfNotExists(); 

      // Create a permissions object. 
      BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); 

      // Include public access in the permissions object. 
      containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); 

      // Set the permissions on the container. 
      container.uploadPermissions(containerPermissions); 

      // Create or overwrite the new file to blob with contents from a local file. 
      /*CloudBlockBlob blob = container.getBlockBlobReference("azure-storage-1.2.0.jar"); 
      File source = new File(filePath); 
      blob.upload(new FileInputStream(source), source.length());*/ 

      String envFilePath = System.getenv("AZURE_FILE_PATH"); 

      //upload list of files/directory to blob storage 
      File folder = new File(envFilePath); 
      File[] listOfFiles = folder.listFiles(); 

      for (int i = 0; i < listOfFiles.length; i++) { 
       if (listOfFiles[i].isFile()) { 
       System.out.println("File " + listOfFiles[i].getName()); 

       CloudBlockBlob blob = container.getBlockBlobReference(listOfFiles[i].getName()); 
       File source = new File(envFilePath+"\\"+listOfFiles[i].getName()); 
       blob.upload(new FileInputStream(source), source.length()); 
       System.out.println("File " + listOfFiles[i].getName()+ " upload successful"); 

       } 
       //directory upload 
       /*else if (listOfFiles[i].isDirectory()) { 
       System.out.println("Directory " + listOfFiles[i].getName()); 

       CloudBlockBlob blob = container.getBlockBlobReference(listOfFiles[i].getName()); 
       File source = new File(file_Path+"\\"+listOfFiles[i].getName()); 
       blob.upload(new FileInputStream(source), source.length()); 
       }*/ 
      } 

     }catch (Exception e) 
     { 
      // Output the stack trace. 
      e.printStackTrace(); 
     } 
    } 
} 

.NET或C#,那么请添加以下代码 “的App.config”

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 

    <system.net> 
    <defaultProxy enabled="true" useDefaultCredentials="true"> 
     <proxy usesystemdefault="true" /> 
    </defaultProxy> 
    </system.net> 

</configuration> 
相关问题