C# Rest Sharp Post错误-基础连接已关闭:服务器已关闭预期保持活动状态的连接

C# Rest Sharp Post错误-基础连接已关闭:服务器已关闭预期保持活动状态的连接,c#,asp.net-mvc,rest,restsharp,C#,Asp.net Mvc,Rest,Restsharp,我有一个MVCAPI(我们称之为API1),它向另一个较小的API(API2)发出请求。它使用Rest-Sharp来实现这一点 我的问题是,API 1第一次调用API 2时,它工作得非常好 但是,如果对API 2进行了另一次调用,那么它将无法报告 “基础连接已关闭:服务器已关闭预期保持活动状态的连接” 如果我回收了website/API 2的应用程序池,那么它又可以正常工作了 我试过其他帖子的一些建议 ServicePointManager.SecurityProtocol = Secu

我有一个MVCAPI(我们称之为API1),它向另一个较小的API(API2)发出请求。它使用Rest-Sharp来实现这一点

我的问题是,API 1第一次调用API 2时,它工作得非常好

但是,如果对API 2进行了另一次调用,那么它将无法报告

“基础连接已关闭:服务器已关闭预期保持活动状态的连接”

如果我回收了website/API 2的应用程序池,那么它又可以正常工作了

我试过其他帖子的一些建议

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
    ServicePointManager.Expect100Continue = false;
    ServicePointManager.DefaultConnectionLimit = 100;
    ServicePointManager.MaxServicePointIdleTime = 600000;
这些都没有帮助

我的代码如下

API 1使用以下代码:

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
        ServicePointManager.Expect100Continue = false;
        ServicePointManager.DefaultConnectionLimit = 100;
        ServicePointManager.MaxServicePointIdleTime = 600000;

        var client = new RestClient(baseApiUrl + "py/apte?employeeReference=" + employeeReference + "&paymentReference=" + paymentReference + "&hours=" + hours + "&rate=" + rate);
        client.Timeout = -1;
        var request = new RestRequest(Method.POST);
        request.AddHeader("Content-Type", "application/json");
        request.Timeout = 600000;

        var response = client.Execute<APIResponse>(request);
        APIResponse apiResponse = apiResponse = response.Data;

        return apiResponse;
ServicePointManager.SecurityProtocol=SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue=false;
ServicePointManager.DefaultConnectionLimit=100;
ServicePointManager.MaxServicePointIdleTime=600000;
var client=new RestClient(baseApiUrl+“py/apte?employeeReference=“+employeeReference+”&paymentReference=“+paymentReference+”&hours=“+hours+”&rate=“+rate”);
client.Timeout=-1;
var请求=新的重新请求(Method.POST);
AddHeader(“内容类型”、“应用程序/json”);
请求超时=600000;
var response=client.Execute(请求);
APIResponse=APIResponse=response.Data;
返回响应;