C# 连接关闭错误
当调试器点击下面的粗体线时,我的web API post方法出现连接关闭错误。其他一切似乎都在起作用。我甚至增加了web配置的时间和长度C# 连接关闭错误,c#,asp.net-web-api,dotnet-httpclient,C#,Asp.net Web Api,Dotnet Httpclient,当调试器点击下面的粗体线时,我的web API post方法出现连接关闭错误。其他一切似乎都在起作用。我甚至增加了web配置的时间和长度 var client = new HttpClient(); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; var uri = new Uri("https://localhost:19810/api/.../insert/"); string message = stri
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;
}
}
@卡尔:你回复我的帖子了吗?我发现了问题所在。我尝试插入一条违反主键约束的记录。谢谢