当我使用 Postman 发出请求时,我得到:
这是我所期待的:
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();
}
我总是在属性数据中得到空值,即使值在 json 响应中也是如此。