[编辑] 我的错误 - 显示错误发生的错误行。
我是 SQL Server 开发人员而不是 .net 开发人员,所以请多多包涵。
在 SSIS (Visual Studio 2017) 中使用脚本任务使用第 3 方 Rest API 并收到以下错误
请求被中止,请求被取消。
这是我正在使用的代码
string responseMessage = null;
string pushResponse = null;
try
{
WebRequest req = WebRequest.Create(post_url);
req.Method = "POST";
req.ContentType = "application/json";
req.Timeout = 600000;
req.Credentials = new NetworkCredential(api_username, api_password);
using (var streamWriter = new StreamWriter(req.GetRequestStream()))
{
string json = "{\r\n\"carCountryCode\": \"" + api_countryCode + "\",\r\n\"carLicenseNumber\": \"" + carLicenseNumber + "\",\r\n\"client\": \"" + api_client + "\"\r\n}";
streamWriter.Write(json);
}
if (req != null)
{
var response = req.GetResponse() as HttpWebResponse;
if (response.StatusCode == HttpStatusCode.OK)
{
System.IO.Stream responseStream = response.GetResponseStream();
if (responseStream != null)
{
var reader = new System.IO.StreamReader(responseStream);
responseMessage = reader.ReadToEnd();
pushResponse = responseMessage;
reader.Close();
responseStream.Close();
response.Close();
}
responseStream.Close();
response.Close();
}
else
{
responseMessage = response.StatusDescription;
//MessageBox.Show("Error:" + responseMessage);
}
//MessageBox.Show("Success: " + pushResponse);
response.Close();
}
}
//catch (Exception e)
catch (Exception ex)
{
Dts.Events.FireError(0, "ERROR", ex.Message, null, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
在线生成错误 - [编辑] 我的错误,之前显示错误的行
var response = req.GetResponse() as HttpWebResponse;
这一直工作到今天早上。我已经检查过,该服务已启动并正在运行。