当我使用邮递员进行请求时,我得到:
这就是我所期待的:
public class Result<TResultType>
{
public int? ErrorId { get; protected set; } // Todo: Use it!!!
public bool Success { get; protected set; }
public ResponseErrorType ErrorType { get; protected set; }
public string Message { get; protected set; }
public TResultType Data { get; protected set; }
}
在这种情况下,TResultType为:
public class SettingsResponse : BaseResponse
{
public string LocationCode { get; set; }
public string Ip { get; set; }
public int Port { get; set; }
public string ApplicationPrinterName { get; set; }
public string MerchantNumber { get; set; }
public string MessageControl { get; set; }
public string PRIN { get; set; }
public string SoftwareName { get; set; }
public string SoftwareVersion { get; set; }
public string SystemNumber { get; set; }
}
我是这样做的:
using (HttpClient client = GetHttpClient())
{
var responseTask = client.GetAsync($"{url}/{paramsStr}");
if (await Task.WhenAny(responseTask, Task.Delay(TimeoutSeconds * 1000)) == responseTask)
{
var response = await responseTask;
return response.IsSuccessStatusCode
? await response.Content.ReadAsAsync<Result<TResponse>>()
: default(Result<TResponse>);
}
return Result<TResponse>.FromTimeout();
}
我总是在属性数据中得到null,即使json响应中有值。