当调试器点击下面的BOLD行时,我的web API post方法会出现连接关闭错误。其他一切似乎都在起作用。我甚至在网络配置中增加了时间和长度。
var client = new HttpClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
var uri = new Uri("https://localhost:19810/api/.../insert/");
string message = string.Empty;
if (client != null)
{
try
{
**var response = await client.PostAsJsonAsync(uri, lookup);**
if (response.IsSuccessStatusCode)
{
message = "Record inserted Successfully";
}
}
catch (OperationCanceledException oce)
{
// because timeouts are still possible
message = oce.InnerException.Message;
}
catch (Exception exc)
{
// Because other things can still go wrong too (HTTP 500, parsing errors)
message = exc.InnerException.Message;
}
}