SSIS C# HTTP GetAsync 不等待响应 [英] SSIS C# HTTP GetAsync not waiting for the response

查看:26
本文介绍了SSIS C# HTTP GetAsync 不等待响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SSIS C# 任务中使用 getAsync(URL).Result 函数.在调试窗口中,我可以看到 Result="{尚未计算}".

代码在过去 1 年中运行良好,但在 API 的新版本发布后停止运行.似乎不是在等待回应.我的代码:

public void Main(){GetRequest(Dts.Variables["User::URL"].Value.ToString());Dts.TaskResult = (int)ScriptResults.Success;}私有静态无效GetRequest(字符串网址){尝试{HttpClient 客户端 = 新的 HttpClient();HttpResponseMessage response = client.GetAsync(url).Result;response.EnsureSuccessStatusCode();}捕获(例外 e){System.Console.WriteLine("捕获异常:" + e.Message);}}

有人能给我一些见解吗?

谢谢

解决方案

谢谢@jdweng

帮助我解决问题的评论副本:

<块引用>

听起来像是 TLS 身份验证问题.五年前,由于安全问题,业界决定取消 TLS 1.0/1.1.今年 6 月,微软推出了禁用 TLS 1.0/1.1 的安全更新,现在要求客户端使用 TLS 1.2/1.3.因此,添加到您的代码以下似乎可以解决问题:ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

I'm using the getAsync(URL).Result function inside an SSIS C# task. In the debug window I can see the Result="{Not yet computed}".

The code is working very well for the last 1 year, although stops working after a new release of the API came up. It seems it's not waiting for the response. MY CODE:

public void Main()
{

    GetRequest(Dts.Variables["User::URL"].Value.ToString());
    Dts.TaskResult = (int)ScriptResults.Success;
}

private static void GetRequest(string url)
{
   try
   {
      HttpClient client = new HttpClient();
      HttpResponseMessage response = client.GetAsync(url).Result;
      response.EnsureSuccessStatusCode();
   }
   catch (Exception e)
   {
      System.Console.WriteLine("Caught Exception: " + e.Message);
   }
}

Can someone give me some insights?

Thank you

解决方案

Thank you @jdweng

Copy of the comment that helps me to solve the issue:

Sounds like a TLS authentication issue. Five years ago the industry decided to eliminate TLS 1.0/1.1 due to security issues. In June this year Microsoft pushed a security update disabling TLS 1.0/1.1 and now require clients to use TLS 1.2/1.3. So adding to your code following seems to solve issue : ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

这篇关于SSIS C# HTTP GetAsync 不等待响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆