解决方案 »

  1.   

    我测试通过的代码(windows gbk,可以参考python-swiftclient --debug -v的等同curl命令输出):
    csharp-swiftusing System;
    using System.IO;
    using System.Collections.Generic;
    using System.Text;using OpenStack.Swift;namespace SwiftClientCSharp
    {
    class Program
    {
    public static void Main(string[] args)
    {
    SwiftClient sc = new SwiftClient();
    sc.DisableSSLCertificateValidation();
    string url="https://192.168.179.61:8080/auth/v1.0";
    string user="system:root";
    string key="testpass";

    Dictionary<string,string> headers = new Dictionary<string, string>();
    Dictionary<string,string> query = new Dictionary<string, string>();


    AuthResponse ar = sc.GetAuth(url,user,key,headers,query,false);

    string token = ar.Headers["x-auth-token"];
    string xurl = ar.Headers["x-storage-url"];



    string srcContainerName = "CSharp中文名";
    string srcObjectName = "CSharp中文名.txt";

    UTF8Encoding utf8 = new UTF8Encoding();
    byte[] utf8bytes = utf8.GetBytes(srcContainerName);

    StringBuilder sb = new StringBuilder();
    foreach (byte tmp in utf8bytes)
    {
    sb.AppendFormat("%{0:X2}",tmp);
    }

    string containerName = sb.ToString();

    sb.Clear();
    utf8bytes = utf8.GetBytes(srcObjectName);
    foreach(byte tmp in utf8bytes)
    {
    sb.AppendFormat("%{0:X2}",tmp);
    }

    string objectName = sb.ToString();
    sb.Clear();



    Stream fstream = new FileStream(srcObjectName,FileMode.Open);

    ContainerResponse cr = sc.PutContainer(xurl,token,containerName,headers,query);

    ObjectResponse or = sc.PutObject(xurl,token,containerName,objectName,fstream,headers,query);

    fstream.Close();

    ContainerResponse cr2 = sc.GetContainer(xurl,token,containerName,headers,query,true);

    Console.Write("Press any key to continue . . . ");
    Console.ReadKey(true);
    }
    }
    }