[英]400 Bad Request on OneFS API POST request
我正在嘗試通過 OneFS REST API 在我們的 Isilon 群集上創建存儲配額。 我正在使用來自前 EMC 工程師的類庫,並添加了我自己的方法來創建配額,但無法弄清楚為什么會返回 400 錯誤。 目前這是通過一個簡單的控制台應用程序發送的,並且相同的有效負載和 URL 在 Postman 中沒有任何問題。 我真的很想繼續使用和構建這個庫,因為很多工作已經完成。 任何幫助或見解將不勝感激。
我從 Main 調用我的 CreateQuota 方法
static void Main(string[] args)
{
//DisplayQuotas();
bool qcontainer = false;
bool qenforced = false;
bool qincludesnaps = false;
bool qthresincludeoverhead = false;
string qtype = "directory";
string qpath = "/path/to/myquota/diectory";
SmartQuotas quotas = new SmartQuotas(service);
quotas.CreateQuota(qcontainer, qenforced, qincludesnaps, qthresincludeoverhead, qtype, qpath);
}
我添加的 CreateQuota 方法利用了另一個類的 DataMemberAttribute - 這是仿照現有的方法創建 SMB 共享。
public Quota CreateQuota(bool container, bool enforced, bool include_snapshots, bool thresholds_include_overhead, string type, string path)
{
Quota quota = new Quota();
quota.Container = container;
quota.Enforced = enforced;
quota.IncludeSnapshots = include_snapshots;
quota.ThresholdsIncludeOverhead = thresholds_include_overhead;
quota.Type = type;
quota.Path = path;
Post<Quota>("/platform/1/quota/quotas", quota);
//quota = GetQuotas()[0];
return quota;
}
這是 Post 方法,它使用 DataContractSerializer,我覺得這是我的問題的一部分。 我只是不確定為什么我發送的正文不會被正確解析,並且在反序列化以查看我的請求會是什么樣子時也遇到問題。
protected void Post<T>(string resource, T body)
{
try
{
// Create a web request object pointing to the Isilon server and Resource String
HttpWebRequest request = _Service.CreateRequest(resource);
request.Method = "POST";
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
serializer.WriteObject(request.GetRequestStream(), (T)body);
// Attempt at reading the stream but throws System.NotSupportedException
//T t2 = (T)serializer.ReadObject(request.GetRequestStream());
// Send the request to the Isilon cluster and get there response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
}
catch(WebException e)
{
Console.WriteLine("This is the WebException from a POST attempt: " + e.Message);
if(e.Status == WebExceptionStatus.ProtocolError)
{
Console.WriteLine("Status Code: {0}", ((HttpWebResponse)e.Response).StatusCode);
Console.Write("Status Description: {0}", ((HttpWebResponse)e.Response).StatusDescription);
}
}
}
這也是 DataContract 類的精簡版本,它在我鏈接到的 Git 存儲庫中可見。
[DataContract]
public class Quota
{
// Enables the SMB shares using the quota directory to see the quota threshold as the share size.
[DataMember(Name = "container", EmitDefaultValue = false)]
public bool Container;
// True if the quota provides enforcement, otherwise an accounting quota
[DataMember(Name = "enforced", EmitDefaultValue = false)]
public bool Enforced;
// True if the quota governs snapshot data as well as head data.
[DataMember(Name = "include_snapshots", EmitDefaultValue = false)]
public bool IncludeSnapshots;
// True if the thresholds apply to the data plus file system overhead that is required to store the data
// (such as physical useage)
[DataMember(Name = "thresholds_include_overhead", EmitDefaultValue = false)]
public bool ThresholdsIncludeOverhead;
// Type of quota - User, group, directory
[DataMember(Name = "type", EmitDefaultValue = false)]
public string Type;
// OneFS path
[DataMember(Name = "path", EmitDefaultValue = false)]
public string Path;
}
結果證明答案相當簡單——閾值對象的模式有一個嵌套值,該值沒有正確形成。 我最終使用 RestSharp 自己從頭開始進行這個調用,並仔細查看了 OneFS API 文檔,這兩個文檔最終幫助我了解了這里發生了什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.