0

当调试器点击下面的 BOLD 行时,我的 Web API 发布方法出现连接关闭错误。其他一切似乎都在工作。我什至增加了网络配置的时间和长度。

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;
    }
}
4

0 回答 0