簡體   English   中英

Rackspace雲文件REST API莫名其妙地收到錯誤的請求響應

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

我正在嘗試編寫一個程序來對機架雲文件進行身份驗證。 下面的命令可以使用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"

但是,我收到一個錯誤的請求(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);

有人有什么想法嗎?

因此,在添加我的json正文時,我需要這樣做:

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

因此,基本上,它試圖序列化我已經序列化的json。 我通過在堆棧溢出中找到其他一些問題發現了這一點。 我要指出的是,RestSharp的所有官方“文檔”都沒有對此進行解釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM