Question

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

Was it helpful?

Solution

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/

OTHER TIPS

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]);
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top