隐式(下方)Web请求的用户代理 [英] User Agent of implicit (underneath) web request

查看:46
本文介绍了隐式(下方)Web请求的用户代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我没有来源的课程从第三方网络服务器下载文件(它是System.Windows.Media.imaging.Bitmapimage)

Hi, I'm downloading a file from third party web server using a class that I do not have sources (it is System.Windows.Media.imaging.Bitmapimage)

当我以下列方式创建BirmapImage实例时:

When I create instance of BirmapImage the following way:

image = new BitmapImage( uri );

image = new BitmapImage(uri);

下载 uri 指向的二进制文件(png图像)。在下面有一个http请求,指定了一些用户代理。


问题是我下载图像的网站要求其客户使用User-Agent识别自己,而不是提供通用标识。 

the binary file (png image) pointed by uri is downloaded. Underneath there is a http request with some user-agent specified.
The problem is that the site from which I download images requires its clients to identify themselves using User-Agent, and not provide generic identification. 

我想将自己呈现为例如  "MyApplication V 0.9。 .Net客户端"

I would like to present myself as e.g.  "MyApplication V 0.9. .Net client"

是否有可能在没有BitmapImage类源的情况下实现这一点?并且仍然让BitmapImage从网址中为我提取文件?

Is it possible to achieve this without having sources of BitmapImage class ?and still having BitmapImage fetching the file for me from the url ?

Michal

推荐答案

创建HttpWebRequest请求  ;并设置UserAgent属性。 

Create HttpWebRequest request and set the UserAgent property. 

BitmapImage b = new BitmapImage();

BitmapImage b = new BitmapImage();

b.StreamSource = request.GetResponse()。GetResponseStream ();

b.StreamSource = request.GetResponse().GetResponseStream();

b.BeginInit();

b.BeginInit();

b.EndInit();

b.EndInit();

http://msdn.microsoft.com/en -us / library / system.windows.media.imaging.bitmapimage.streamsource.aspx

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage。 beginin it.aspx

我不建议的另一个选择是做一些复杂的事情,比如在配置文件中设置WebRequest模块:

Another option I wouldn't suggest would be to do something complicated like setting a WebRequest module in a config file:

http://msdn.microsoft.com/en-us/library/bc0fhzk5 .aspx

 


这篇关于隐式(下方)Web请求的用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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