简体   繁体   English

Rackspace云文件REST API莫名其妙地收到错误的请求响应

[英]Rackspace cloud files REST api inexplicably getting bad request response

I am trying to write a program to authenticate to rackspace cloud files. 我正在尝试编写一个程序来对机架云文件进行身份验证。 The following command works with curl just fine: 下面的命令可以使用curl:

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: 但是,我收到一个错误的请求(400)错误,并带有以下代码:

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? 有人有什么想法吗?

So, when adding my json body I need to do so as follows: 因此,在添加我的json正文时,我需要这样做:

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

So basically, it was trying to serialize my already serialized json. 因此,基本上,它试图序列化我已经序列化的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. 我要指出的是,RestSharp的所有官方“文档”都没有对此进行解释。

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

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