【问题标题】:SSIS underlying connection was closed: An unexpected error occurred on a sendSSIS 基础连接已关闭:发送时发生意外错误
【发布时间】:2022-01-17 09:52:42
【问题描述】:

我正在尝试调用 SSIS 包中的 API。我能够在常规单元测试类中使用相同的代码,并且一切都按预期工作。我尝试了一些我在堆栈溢出中看到的建议,但没有运气。

GetRequestStream() 失败

错误:底层连接已关闭:发送时发生意外错误。 内部错误消息:无法从传输连接中读取数据:现有连接已被远程主机强制关闭。

代码:

            var request = (HttpWebRequest)WebRequest.Create(requestURL);
            var muaRequest = new MUARequest
            {
                designationType = "MUAP"
            };
            var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(muaRequest));

            request.Method = "POST";
            request.ContentType = "application/json";
            request.ContentLength = data.Length;
            request.Timeout = Timeout.Infinite;
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            ServicePointManager.Expect100Continue = true;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol | System.Net.SecurityProtocolType.Tls12;
            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            //var response = (HttpWebResponse)request.GetResponse();
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        using (var reader = new StreamReader(responseStream))
                        {
                            var content = reader.ReadToEnd();
                            results = JsonConvert.DeserializeObject<Results>(content);
                        }
                    }
                }
                else
                {
                    results.ErrorCode = "Http Request Failed.";
                }
            }

【问题讨论】:

  • 您能否使用邮递员成功进行 POST 调用?
  • @FaisalMehboob 是的,我发现了在创建 http web 请求之前需要放置安全协议的问题

标签: c# ssis httpwebrequest httpwebresponse


【解决方案1】:

需要在创建 Web 请求之前调用安全协议的声明。之后就可以了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多