gpt4 book ai didi

azure - PostAsync 在控制台应用程序中工作 - 不在 SSIS 包内工作

转载 作者:行者123 更新时间:2023-12-03 04:04:52 24 4
gpt4 key购买 nike

我有一个相当麻烦的问题。我正在尝试通过 SSIS 在 Azure 中发布 Webjob。以下请求适用于我的测试应用程序,它是一个控制台应用程序。

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 发出发布请求以触发它。

当我将以下代码放入 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。

您知道如何解决此问题吗?我被困在这个问题上,我开始兜圈子试图解决它。我唯一能想到的是网络问题,但我不知道如何验证这一点。

最佳答案

我找到了此问题的解决方案:Need to add SecurityProtocol

解决方案的引用:

The key is adding security protocol and apply all types:ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | Tls32 |..This resolved the issue

可以在这里找到更强大的解决方案:Configure ServicePointManager.SecurityProtocol through AppSettings

关于azure - PostAsync 在控制台应用程序中工作 - 不在 SSIS 包内工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60452745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com