Question

I am trying to write a program to authenticate to rackspace cloud files. The following command works with curl just fine:

curl -k -X POST https://identity.api.rackspacecloud.com/v2.0/tokens -d '{ "auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"myusername","apiKey":"mykey"}}}' -H "Content-type: application/json"

However, I get a bad request (400) error with the following code:

var client = new RestClient("https://identity.api.rackspacecloud.com/v2.0");
var request = new RestRequest("tokens", Method.POST);
request.RequestFormat = DataFormat.Json;

string serText = "{ \"auth\":{\"RAX-KSKEY:apiKeyCredentials\"{\"username\":\"myusername\",\"apiKey\":\"mykey\"}}}";
request.AddBody(serText);
RestResponse response = (RestResponse)client.Execute(request);

Anybody have any ideas?

Was it helpful?

Solution

So, when adding my json body I need to do so as follows:

request.AddParameter("application/json", serText, ParameterType.RequestBody);

So basically, it was trying to serialize my already serialized json. I found this out by finding some other questions on stack overflow. I would point out this is not explained at all the official "documentation" for RestSharp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top