I want to do a PUT request via a REST API. I've got the access_token, which should be correct. I'm trying to upload a JSON object of relation, but I get the following error:
restsharp PUT request error:
“StatusCode: InternalServerError, Content-Type: application/json, Content-Length: -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);
}
I suggest reading the docs, really.
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.