我有一个相当麻烦的问题。我正在尝试通过SSIS在Azure中发布Web作业。以下请求适用于我的测试应用程序,它是一个控制台应用程序。
public static void Main(string[] args)
{
string ApiUrl = "HTTPS";
string call = "triggeredwebjobs/JOB NAME/run";
string result = string.Empty;
string userPswd = "USER" + ":" + "PASSWORD";
userPswd = Convert.ToBase64String(Encoding.Default.GetBytes(userPswd));
var response = new HttpResponseMessage(HttpStatusCode.NotFound);
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(ApiUrl);
client.Timeout = TimeSpan.FromMinutes(30);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", userPswd);
response = client.PostAsync(call, new StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json")).Result;
}
}
catch (Exception ex)
{
throw ex;
}
}
}
上面的代码是成功的,并向Azure中的目标webjob发出post请求以触发它。
当我将以下代码放入SSIS包中并尝试从Visual Studio运行它时,它不起作用。
public void Main()
{
// TODO: Add your code here
try
{
string ApiUrl = "HTTPS";
string call = "triggeredwebjobs/JOB NAME/run";
string result = string.Empty;
string userPswd = "USER" + ":" + "PASSWORD";
userPswd = Convert.ToBase64String(Encoding.Default.GetBytes(userPswd));
var response = new HttpResponseMessage(HttpStatusCode.NotFound);
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(ApiUrl);
client.Timeout = TimeSpan.FromMinutes(30);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", userPswd);
response = client.PostAsync(call, new StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json")).Result;
}
}
catch (Exception ex)
{
Dts.Events.FireError(0, "ERROR", ex.Message, null, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
我得到状态代码404。
你知道如何纠正这个问题吗?我陷入了困境,我开始绕圈子试图解决它。我唯一能想到的就是网络问题,但我不知道如何验证。
我找到了这个问题的解决方案:需要添加SecurityProtocol
来自解决方案的引文:
关键是添加安全协议并应用所有类型:ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12|Tls32|。。这解决了问题
可以在此处找到更强大的解决方案:通过AppSettings 配置ServicePointManager.SecurityProtocol