我正在调用rest Web服务,并且99%的时间都可以正常工作,但是一段时间后,我收到错误消息:“没有MediaTypeFormatter可用于从媒体内容中读取类型为“订单”的对象输入“ text / html”” 这是我的代码。 C#Core 2.1
我正在使用IHttpClientFactory调用服务。
public APIvtex(IHttpClientFactory clientFactory)
{
_clientFactory = clientFactory;
}
//和类中的方法
public Order GetOrder(string orderId)
{
Order OutPut = null;
string url = "http://xxxxx.xxxxxxx.com.br/api/oms/pvt/orders/";
url = url + orderId;
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add("X-VTEX-API-AppKey", "xxxxxxxxxxx");
request.Headers.Add("X-VTEX-API-AppToken", "xxxxxxxxxxxxxxxxxx");
request.Headers.Add("Accept", "application/json");
var client = _clientFactory.CreateClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = client.SendAsync(request);
response.Wait();
if (response.IsCompletedSuccessfully)
{
response.Result.EnsureSuccessStatusCode();
var task = response.Result.Content.ReadAsAsync<Order>();
task.Wait();
OutPut = task.Result;
}
return OutPut;
}