首页 文章

使用.NET 4.0或4.5.X时,图像无法从Twitch static-cdn加载

提问于
浏览
0

我有一个WPF桌面应用程序,我用它来使用他们的API在Twitch上导航游戏和流 . 大约2周前(2018年2月中旬/后期)我开始注意到流预览图像不再加载( <Image /> 标签在布局中没有占用空间) .

图像加载非常简单 . 为了演示,我选择了一个24/7流 .

<Image Source="https://static-cdn.jtvnw.net/previews-ttv/live_user_esl_sc2-640x360.jpg" />

此URL来自API,可在浏览器中正常运行 . 在测试过程中,我创建了一个基本的WPF应用程序 .

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Image Source="https://static-cdn.jtvnw.net/previews-ttv/live_user_esl_sc2-640x360.jpg" />
    </Grid>
</Window>

这最终起作用,我最终意识到这是因为新项目有一个.NET 4.6.1的目标框架 . 将其切换到4.5.X会导致它产生与其他应用程序相同的结果 . 将第一个应用程序切换到4.6.X会使其再次运行 . .NET 4.0也失败了 . 其他网站(例如Imgur)无故障地工作 . 也许还值得注意的是,在任何.NET框架上使用Twitch url时,设计器窗口中都没有预览图像,但Imgur还有一个 .

问题出现在两台Windows 10设备和一台Windows 7设备上 . 我相信其中一个Windows 10设备有定期的Windows更新(可能已禁用,不确定),而其他两个更新设置为仅手动 .

是什么导致了这种行为?

1 回答

  • 0

    看来Twitch现在通过HTTP / 2提供图像 . 我相信旧版.NET下的HTTP请求默认使用SSL3,并且被Twitch拒绝 .

    除了将.NET版本升级到4.6.x或更高版本之外,设置安全协议还可以解决问题:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    

相关问题