需要授权的图像源 URI [英] Image source URI requiring authorization

查看:27
本文介绍了需要授权的图像源 URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 WPF Window 上,我有一个 Image,其 UriSource 设置为 Internet 上某些图像的 URL.

On my WPF Window I have an Image whose UriSource is set to the URL of some image on the internet.

<Image>
    <Image.Source>
        <BitmapImage UriSource="http://tinyurl.com/anmucph" />
    </Image.Source>
</Image>

当我在 Internet 上使用可公开访问的图像时,一切正常:WPF 框架执行必要的 HTTP GET 请求并显示图像.

Everything works properly when I use a publicly accessible image on the internet: the WPF framework does the necessary HTTP GET request and displays the image.

我想要做的是使用 UriSource 这是一个 URL,它要求 HTTP GET 请求带有授权标头.(我有我想要使用的必需的 Authorization 标头字符串.)

What I want to do is use a UriSource that is a URL that requires the HTTP GET request to come with an Authorization header. (I have the required Authorization header string that I want to use.)

如何使用需要授权的 UriSource?WPF中是否有内置的东西?或者这是否需要自定义解决方案?如果是这样,我如何挂钩 WPF 框架以提供用于执行 HTTP GET 的自定义逻辑?

How do I use a UriSource that requires authorization? Is there something built into WPF? Or does this require a custom solution? If so, how can I hook into the WPF framework to provide custom logic for performing the HTTP GET?

推荐答案

WPF 中内置的工具无法做到这一点.

This can't be done with the tools built into WPF.

另一种方法是创建一个轻量级的本地 HTTP 代理,它具有单个

An alternative would be to create a lightweight and local HTTP proxy that has a single

  • GET http://localhost:####/proxy?uri={uri}&authorization={authorization}

操作(其中端口#### 在防火墙后面)反过来又使

operation (where port #### is behind firewall) that in turn makes a

  • GET {uri}

使用提供的授权标头值请求.

request with the supplied authorization header value.

然后您可以将 UriSource 设置为 http://localhost:####/proxy?uri=X&authorization=Y 其中 X 是要显示的受保护资源的 URI 编码 URI,Y 是与 GET 请求一起发送的 URI 编码授权标头.

You could then set UriSource to http://localhost:####/proxy?uri=X&authorization=Y where X is the URI-encoded URI of the secured resource you want to show and Y is the URI-encoded authorization header to send with the GET request.

这篇关于需要授权的图像源 URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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