Picturebox,Image.FromStream,WebRequest - 总是不起作用 [英] Picturebox, Image.FromStream, WebRequest - Doesn't allways work

查看:51
本文介绍了Picturebox,Image.FromStream,WebRequest - 总是不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生


我希望你能给我一个这个小问题的暗示。


事情是,我有一个lang time喜欢 www.washintonpost.com 上的漫画,

我总是通过他们的主页开始新的一天。


有一天,我想:为什么不用C#制作一个小程序,

只是向我展示了条带的.gif图片?

所以我做了。或者,更准确地说,我试图这样做。


实际上,这很简单。我想展示一条Non

Sequitur从2008年5月30日起。

可以直接在浏览器中看到,使用以下链接:

http://wpcomics.washingtonpost.com/c...nq/2008/05/30/


显示属性我,直接链接到.gif文件的链接是

这个:

http://wpcomics.washingtonpost.com/f...0/nq080530.gif


可以通过这种方式在图片框中查看条带:


picturebox1.Image = Image.FromStream(WebRequest.Create(" http://

wpcomics.washingtonpost.com/feature/08/05/30/

nq080530.gif")。GetResponse()。GetResponseStream());


如果我想要另一个日期的另一个条带,我只需更改网址的日期部分




到目前为止,非常好。


但是,我想看看Hagar the Horrible和Hagar the Horrible。太。浏览器链接到

的相同日期是:

http://www.washingtonpost.com/wp-srv...&date=20080530


但是这里开始出现问题:属性在地带上:

http:/ /est.rbma.com/content/Hagar_Th...?date=20080530


直接在浏览器中,它运行正常。

但是在图片框中使用它不是!


我能做些什么来完成这项工作?

欢迎任何有建设性的意见!


(它_should_是可能的!一位朋友告诉我,其他任何其他

程序都可以做,我也可以用C#做​​。)


真诚/最好的问候

Mads Aggerholm

解决方案

On Mon,02 Jun 2008 11:01:09 -0700,Mads Aggerholm

< ma ************ @ gmail.comwrote:


[ ...]

但是这里开始出现问题:属性在地带上:

http:/ /est.rbma.com/content/Hagar_Th...?date=20080530


直接在浏览器中,它运行正常。

但在图片框中使用它不行!



定义不。什么,确切地说,不起作用?


我能做些什么来完成这项工作?

欢迎任何有建设性的意见!


(它_should_有可能!一位朋友告诉我,其他任何其他

程序都可以做,我也可以用C#做​​。)



我没有仔细研究过这个特殊情况。但是,你的

朋友的建议只能到目前为止。


特别是,你的C#程序可能没有_exactly_另一个

程序正在做。它_could_,但它可能不是。


某些Web服务器已配置为可以检索某些内容

仅在原始源的上下文中页。因此,

的检索发生在一个上下文中,这个上下文看起来像Web浏览器这样的服务器正在获得

数据将起作用,而其他人则不会。网络服务器将

在其他情况下拒绝提供数据。


你没有费心去描述任何关于什么的细节不工作,所以

我不可能肯定地说这是在继续。但如果它是
,你必须确保你的程序检索

中的数据与网络浏览器完全相同(获取原始页面) ,

为图形设置引用者等)。最简单的方法就是运行网络监控程序(Wireshark程序

在这方面可能有用)来查看发送和接收的数据

当你在网络浏览器中查看漫画时,你的网页浏览器。


当然,你的问题也可能完全是你的问题

不同。如果没有更多细节,你真的不可能说。

你。关于你的代码正在做什么以及它是如何失败的非常具体的信息将是最小的,并且最好的解释将包括

简洁但完整的代码示例演示了这个问题。


Pete


http://est.rbma.com/content/Hagar_Th...?date=20080530


直接在浏览器中,它运行正常。

但是在图片框中使用它不行!


什么可以我做这个工作?



Youi必须看到上面的网址返回的内容,它可能会返回一个仅包含图片的网页

,但仍然是一个网页。因为你的

代码不起作用

我现在无法检查,因为我的公司防火墙阻止了该网站


6月2日下午2:01,Mads Aggerholm< mads.aggerh ... @ gmail.comwrote:


你好先生


我希望你能给我一个这个小问题的暗示。


事情是,我有一段时间享受www.washintonpost.com上的漫画,

我总是通过他们的主页开始新的一天。


有一天,我想:为什么不在C#做一个小程序,那个

只是向我展示了条带的.gif图片?

所以我做到了。或者,更准确地说,我试图这样做。


实际上,这很简单。我想展示一条Non

Sequitur从2008年5月30日起。

可以直接在浏览器中看到,使用以下链接:

http://wpcomics.washingtonpost.com/c...nq/2008/05/30/


显示属性我,直接链接到.gif文件的链接是

这个:

http://wpcomics.washingtonpost.com/f...0/nq080530.gif


可以通过这种方式在图片框中查看条带:


picturebox1.Image = Image.FromStream(WebRequest.Create(" http://

wpcomics.washingtonpost.com/feature/08/05/30/

nq080530.gif")。GetResponse()。GetResponseStream());


如果我想要另一个日期的另一个条带,我只需更改网址的日期部分




到目前为止,非常好。


但是,我想看看Hagar the Horrible和Hagar the Horrible。太。浏览器链接到

的相同日期是:

http://www.washingtonpost.com/wp-srv...cs/king.html?n ...


但是这里开始出现问题:属性在地带上:

http:/ /est.rbma.com/content/Hagar_Th...?date=20080530


直接在浏览器中,它运行正常。

但是在图片框中使用它不是!


我能做些什么来完成这项工作?

欢迎任何有建设性的意见!


(它_should_是可能的!一位朋友告诉我,其他任何其他

程序都可以做,我也可以用C#做​​。)


真诚/最好的问候

Mads Aggerholm



尝试在Web请求标题中设置User-agent。如果确实没有工作,那么请使用fiddler并查看您的浏览器发送到网站的内容

并从网页请求中发送相同的信息。


Hello Sirs

I hope you can give me a hint to this little problem.

The thing is, I have for a lang time enjoyed the comics on www.washintonpost.com,
and I allways start the day by going to their homepage.

One day, I thought: Why not just make a little program in C#, that
just shows me the .gif-picture of the strip?
And so I did. Or, more correctly, I tried to do.

Actually, it''s quite simple. I want to show the strip of "Non
Sequitur" from the 30. of may 2008.
It can be seen directly in a browser, using this link:

http://wpcomics.washingtonpost.com/c...nq/2008/05/30/

Showing "Properties" thell me, the link directly to the .gif-file is
this:

http://wpcomics.washingtonpost.com/f...0/nq080530.gif

The strip can be viewed in a picturebox this way:

picturebox1.Image = Image.FromStream(WebRequest.Create("http://
wpcomics.washingtonpost.com/feature/08/05/30/
nq080530.gif").GetResponse().GetResponseStream());

If I want another strip from another date, I just change the date-part
of the url.

So far, so good.

However, I''d like to see "Hagar the Horrible" too. Browser link to the
same date is:

http://www.washingtonpost.com/wp-srv...&date=20080530

But here starts the problem: "Properties" on the strip is:

http://est.rbma.com/content/Hagar_Th...?date=20080530

Directly in a browser, it works fine.
But using it in a picturebox does not!

What can I do to make this work??
Any constructive input is welcome!

(It _should_ be possible! A friend told me once, that anything other
programs can do, I can do too in C#.)

Sincerely / Best regards
Mads Aggerholm

解决方案

On Mon, 02 Jun 2008 11:01:09 -0700, Mads Aggerholm
<ma************@gmail.comwrote:

[...]
But here starts the problem: "Properties" on the strip is:

http://est.rbma.com/content/Hagar_Th...?date=20080530

Directly in a browser, it works fine.
But using it in a picturebox does not!

Define "does not". What, exactly, doesn''t work?

What can I do to make this work??
Any constructive input is welcome!

(It _should_ be possible! A friend told me once, that anything other
programs can do, I can do too in C#.)

I haven''t examined this particular scenario closely. However, your
friend''s advice can only be taken so far.

In particular, your C# program may not be doing _exactly_ what another
program is doing. It _could_, but it probably isn''t.

Some web servers are configured so that certain content is retrievable
only in the context of the original source page. So, retrievals that
occur in a context that looks to the server like a web browser is getting
the data will work, while others will not. The web server will
intentially refuse to provide the data in the other cases.

You didn''t bother to describe any specifics about what''s not working, so
it''s impossible for me to say for sure that this is going on. But if it
is, you''ll have to make sure that your program retrieves the data in
exactly the same way that a web browser would (getting the original page,
setting the "referrer" for the graphics, etc.). The simplest way to do
this would be to run a network monitor program (the Wireshark program
might be useful in this respect) to look at what data is sent and received
by your web browser when you look at the comic in your web browser.

Of course, it''s also possible that your problem is something entirely
different. It''s really not possible to say without more details from
you. Very specific information as to what your code is doing and how it
fails would be the minimum, and the best explanation would include a
concise-but-complete code sample that demonstrates the issue.

Pete


http://est.rbma.com/content/Hagar_Th...?date=20080530

Directly in a browser, it works fine.
But using it in a picturebox does not!

What can I do to make this work??

Youi have to see what the above URL return, it might return a webpage
with only the image, but a webpage nevertheless. Because of that your
code does not work
I cannot check it now as that website is blocked by my company firewall


On Jun 2, 2:01 pm, Mads Aggerholm <mads.aggerh...@gmail.comwrote:

Hello Sirs

I hope you can give me a hint to this little problem.

The thing is, I have for a lang time enjoyed the comics onwww.washintonpost.com,
and I allways start the day by going to their homepage.

One day, I thought: Why not just make a little program in C#, that
just shows me the .gif-picture of the strip?
And so I did. Or, more correctly, I tried to do.

Actually, it''s quite simple. I want to show the strip of "Non
Sequitur" from the 30. of may 2008.
It can be seen directly in a browser, using this link:

http://wpcomics.washingtonpost.com/c...nq/2008/05/30/

Showing "Properties" thell me, the link directly to the .gif-file is
this:

http://wpcomics.washingtonpost.com/f...0/nq080530.gif

The strip can be viewed in a picturebox this way:

picturebox1.Image = Image.FromStream(WebRequest.Create("http://
wpcomics.washingtonpost.com/feature/08/05/30/
nq080530.gif").GetResponse().GetResponseStream());

If I want another strip from another date, I just change the date-part
of the url.

So far, so good.

However, I''d like to see "Hagar the Horrible" too. Browser link to the
same date is:

http://www.washingtonpost.com/wp-srv...cs/king.html?n...

But here starts the problem: "Properties" on the strip is:

http://est.rbma.com/content/Hagar_Th...?date=20080530

Directly in a browser, it works fine.
But using it in a picturebox does not!

What can I do to make this work??
Any constructive input is welcome!

(It _should_ be possible! A friend told me once, that anything other
programs can do, I can do too in C#.)

Sincerely / Best regards
Mads Aggerholm

Try setting the User-agent in the web request header. if that does
not work then use fiddler and see what your browser sends to the site
and you send the same info from you web request.


这篇关于Picturebox,Image.FromStream,WebRequest - 总是不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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