0

任何人都可以在不使用 AWS sdk for .net 的情况下帮助我在 c# 中使用这个 REST api“描述桉树实例”示例吗?我给你我的示例代码。此代码在 aws 中成功运行,但在 eucalyptus 中它们给出“404 not found”错误。

    protected void Page_Load(object sender, EventArgs e)
    {
        EucaListInstance("xyx/services/Eucalyptus"); 
    }

    private void ListEucaInstance(string inboundQueueUrl)
    {

        // Create a request for the URL.        
        string date = System.DateTime.UtcNow.ToString("s");
        string stringToSign = string.Format("DescribeInstances" + date);
        string signature = CalculateEucaSignature(stringToSign, true);

        StringBuilder sb = new StringBuilder();
        sb.Append(inboundQueueUrl);
        sb.Append("?Action=DescribeInstances");
        sb.Append("&Version=2013-10-15");
        sb.AppendFormat("&AWSAccessKeyId={0}", m_EucaAccessKeyID);
        sb.AppendFormat("&Expires={0}", date);
        sb.AppendFormat("&Signature={0}", signature);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sb.ToString());
        HttpWebResponse response = null;
        Stream dataStream = null;
        StreamReader reader = null;

        try
        {
            request.Credentials = CredentialCache.DefaultCredentials;

            response = (HttpWebResponse)request.GetResponse();

            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();

            // Open the stream using a StreamReader for easy access.
            reader = new StreamReader(dataStream);

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            // Cleanup the streams and the response.
            if (reader != null)
                reader.Close();

            if (dataStream != null)
                dataStream.Close();

            if (response != null)
                response.Close();
        }

    }

    private string CalculateEucaSignature(string data, bool urlEncode)
    {
        ASCIIEncoding ae = new ASCIIEncoding();
        HMACSHA1 signature = new HMACSHA1(ae.GetBytes(m_EucaSecretKey));
        string retSignature = Convert.ToBase64String(signature.ComputeHash(ae.GetBytes(data.ToCharArray())));
        return urlEncode ? HttpUtility.UrlEncode(retSignature) : retSignature;
    }
4

1 回答 1

1

如果您将请求发送到错误的 URL,您将收到 404 错误。我会验证您是否发送到正确的 URL,该 URL 通常类似于:

http://eucalyptus.your.domain.here.example.com:8773/services/Eucalyptus

您可以通过在您的eucarc 文件中查找 EC2_URL 值或运行“euca-describe-services -T eucalyptus”管理命令(在最高 4.0 的版本中,对于 4.0 及更高版本,您将使用“-T 计算”)

于 2014-04-30T22:55:40.557 回答