简体   繁体   English

CloudFiles-Rackspace连接错误C#

[英]CloudFiles - Rackspace connection error c#

I am trying to connect to rackspace using their api and passing my username and api key but i get this error : 我正在尝试使用其api连接到机架并传递我的用户名和api密钥,但出现此错误:

The remote server returned an error: (401) Unauthorized.

here is my code : 这是我的代码:

        UserCredentials userCreds = new UserCredentials("myusername", "myapikey");
        Connection connection = new Connection(userCreds);

I have followed this tutorial : 我遵循了本教程:

http://www.rackspace.com/knowledge_center/index.php/Sample_CSharp_Application

have asked their support and they say we can connect with same key using curl...and they couldnt provide much help. 要求他们的支持,他们说我们可以使用curl来连接同一个钥匙...他们不能提供太多帮助。

anyone has any idea? 有谁有任何想法?

thanks 谢谢

for anyone else who got same problem here i found the solution, you basically need to include the api uri : 对于在这里找到相同问题的其他人,我找到了解决方案,您基本上需要包括api uri:

http://blog.chmouel.com/2011/01/04/how-to-use-the-rackspace-cloud-uk-api/ http://blog.chmouel.com/2011/01/04/how-to-use-the-rackspace-cloud-uk-api/

Your sample works but I was looking for a direct way, without the wrapper. 您的示例有效,但我一直在寻找一种直接的方法,而无需使用包装器。 This seems to work as well, and uses direct restful access to the Rackspace API. 这似乎也可以正常工作,并使用对Rackspace API的直接静态访问。

Hope it helps. 希望能帮助到你。 Cheers. 干杯。

        string url = "https://auth.api.rackspacecloud.com/v1.0";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Headers.Add("X-Auth-User:" + userName);
        request.Headers.Add("X-Auth-Key:" + apiKey);
        request.Method = "GET";

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            string[] keys = response.Headers.AllKeys;

            foreach (var k in keys)
                Console.WriteLine(response.Headers[k]);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM