4,103 questions
besides all the coding errors, StatusCode is a string, and the methods return an IRestResponse
as you are using callback rather than await, chenter code hereange the code to:
public async Task<IRestResponse> HitAPI(JsonData jsonSend) {
var client = new RestClient("");
var request = new RestRequest("", Method.Post):
request.AddParameter("application/json; charset=utf-8", jsonSend, ParameterType.RequestBody);
request.RequestFormat.= DataFormat.Json;
return client.ExecuteAsync<IRestResponse>(request, response =>
{
if (response.StatusCode == System.Net.HttpStatusCode.Ok)
{
//it work
return new SomeRestResponse
{
....
}
}
else
{
//no work
return new FailedRestResponse
{
....
}
}
});
}
but using await would be cleaner:
public async Task<IRestResponse> HitAPI(JsonData jsonSend) {
var client = new RestClient("");
var request = new RestRequest("", Method.Post):
request.AddParameter("application/json; charset=utf-8", jsonSend, ParameterType.RequestBody);
request.RequestFormat.= DataFormat.Json;
var response = await client.ExecuteAsync<IRestResponse>(request);
if (response.StatusCode != System.Net.HttpStatusCode.Ok)
{
//no work
return new FailedRestResponse
{
....
}
}
//it work
return new SomeRestResponse
{
....
}
}
where SomeRestResponse and FailedRestResponse are implementations of IRestResponse