簡體   English   中英

restsharp PUT 請求錯誤-->“StatusCode: InternalServerError, Content-Type: application/json, Content-Length: -1)”

[英]restsharp PUT request error --> "StatusCode: InternalServerError, Content-Type: application/json, Content-Length: -1)"

我想通過 REST API 執行 PUT 請求。 我有 access_token,應該是正確的。 我正在嘗試上傳關系的 JSON 對象,但出現以下錯誤:

restsharp PUT 請求錯誤:

“狀態代碼:內部服務器錯誤,內容類型:應用程序/json,內容長度:-1)”

public void Store(HiveClient hiveClient,string _putUrl, string _url, string _clientId, string _clientSecret, HiveObject objToStore)
{
    hiveClient = new HiveClient(_url, _clientId, _clientSecret);
    hiveClient.CheckIfFileExists();
    string token = hiveClient.restToken;
    HiveObject hiveObject = objToStore;
    var json = JsonConvert.SerializeObject(hiveObject);
    RestClient restClient = new RestClient(_putUrl);
    RestRequest request = new RestRequest(Method.PUT);
    request.AddHeader("Authorization", token);
    request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
    request.AddJsonBody(json);
    request.RequestFormat = DataFormat.Json;
    IRestResponse respons = restClient.Execute<HiveObject>(request);
    var deserialize = new JsonDeserializer();
    var output = deserialize.Deserialize<Dictionary<string, string>>(respons);
} 

我建議閱讀文檔,真的。

public void Store(string _putUrl, string _url, string _clientId, string _clientSecret, HiveObject objToStore)
{
    var hiveClient = new HiveClient(_url, _clientId, _clientSecret);
    hiveClient.CheckIfFileExists();
    string token = hiveClient.restToken;

    var restClient = new RestClient(_putUrl);
    var request = new RestRequest()
        .AddHeader("Authorization", token)
        .AddJsonBody(objToStore);

    var result = restClient.Put<Dictionary<string, string>>(request);
} 

暫無
暫無

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

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