简体   繁体   中英

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 :

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.

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 :

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.

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]);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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