繁体   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