我一直在尝试使用RestSharp Library来发出请求,但是当我尝试发出POST请求时,这个错误不断出现!!
以下是代码:
private readonly string contentType = "application/json";
try
{
var restClient = new RestClient(new Uri(InvoiceExpressURLS.URL_createClient));
string clientJsonRequest =
JsonConvert.SerializeObject(
JsonConvert.DeserializeObject("{\"client\":" + JsonConvert.SerializeObject(newClient) + "}")
);
var request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-Type", contentType);
request.AddJsonBody(clientJsonRequest);
var restResponse = await restClient.ExecuteTaskAsync<object>(request);
if (restResponse.IsSuccessful)
{
response.responseObject = restResponse.Data;
response.responseMessage = string.Format("The client \"{0}\" was successfuly created.", newClient.name);
}
else
{
response.responseStatus = restResponse.StatusCode;
response.responseMessage = restResponse.ErrorMessage;
}
}
catch (Exception e)
{
response.responseStatus = HttpStatusCode.InternalServerError;
response.responseMessage = e.Message;
response.responseObject = e;
}