SSIS 底层连接已关闭:发送时发生意外错误
SSIS underlying connection was closed: An unexpected error occurred on a send
我正在尝试调用 SSIS 包中的 API。我能够在常规单元测试 class 中使用相同的代码,并且一切都按预期工作。我尝试了一些我在堆栈溢出中看到的建议,但没有成功。
在 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.";
}
}
需要在创建网络请求之前调用安全协议的声明。之后就可以了
我正在尝试调用 SSIS 包中的 API。我能够在常规单元测试 class 中使用相同的代码,并且一切都按预期工作。我尝试了一些我在堆栈溢出中看到的建议,但没有成功。
在 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.";
}
}
需要在创建网络请求之前调用安全协议的声明。之后就可以了