473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Picturebox, Image.FromStrea m, WebRequest - Doesn't allways work

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.Ima ge = Image.FromStrea m(WebRequest.Cr eate("http://
wpcomics.washin gtonpost.com/feature/08/05/30/
nq080530.gif"). GetResponse().G etResponseStrea m());

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
Jun 27 '08 #1
12 2917
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
Jun 27 '08 #2
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
Jun 27 '08 #3
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.washinton post.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.Ima ge = Image.FromStrea m(WebRequest.Cr eate("http://
wpcomics.washin gtonpost.com/feature/08/05/30/
nq080530.gif"). GetResponse().G etResponseStrea m());

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.
Jun 27 '08 #4
Hi Pete, thanks for the quick answer.

On 2 Jun., 20:19, "Peter Duniho" <NpOeStPe...@nn owslpianmk.comw rote:
On Mon, 02 Jun 2008 11:01:09 -0700, Mads Aggerholm *

<mads.aggerh... @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?
It actually comes up with a little bitmap image in my picturebox
(that's also standard like if I try a date that doesn't exist) saying:
"Content Currently Unavailable".

I am afraid I can not explain it any better.
You didn't bother to describe any specifics about what's not working, so *
Sorry about that.
Actually I have made it very simple:
I've made a C#-form, with a picturebox in it.
The code is just this:

picturebox1.Ima ge = Image.FromStrea m(WebRequest.Cr eate("http://
est.rbma.com/content/Hagar_The_Horri ble?
date=20080530") .GetResponse(). GetResponseStre am());

And I get the failure-bitmap.

When I change the code to this:

picturebox1.Ima ge = Image.FromStrea m(WebRequest.Cr eate("http://
wpcomics.washin gtonpost.com/feature/08/05/30/
nq080530.gif"). GetResponse().G etResponseStrea m());

the result is the comic strip in the picturebox - no problems.
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.
I'll give that a try.
Thanks for your input, Pete.

Sincerely / Best regards
Mads Aggerholm
Jun 27 '08 #5
On Mon, 02 Jun 2008 11:38:56 -0700, Ignacio Machin ( .NET/ C# MVP )
<ig************ @gmail.comwrote :
>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
For what it's worth, I just tried the link, and the server redirected to
this URL: http://est.rbma.com/content_server/noreferer.gif

That suggests that my previous guess was reasonably accurate: the server
is actively rejecting the request, because it's not being made in a way
that appears to come from a proper browser implementation in which the
original source link is hosted.

Ironically, if the OP's program had more completely handled the HTTP
protocol correctly, it would have received a GIF image with a very
specific error message in it. :) I would have thought that the
HttpRequest class would deal with this automatically, so maybe the OP is
using some lower-level class and failing to handle the HTTP stuff
appropriately. Of course, without a code sample, there's no way to know..

Pete
Jun 27 '08 #6
On Jun 2, 2:47 pm, parez <psaw...@gmail. comwrote:
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.washinton post.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.Ima ge = Image.FromStrea m(WebRequest.Cr eate("http://
wpcomics.washin gtonpost.com/feature/08/05/30/
nq080530.gif"). GetResponse().G etResponseStrea m());
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.
I tried going to http://est.rbma.com/content/Hagar_Th...?date=20080530
and i got an image which said no referer.

so i created an html page with that image as the source and opened
it and it worked.

which means that the image server is only checking for a referrer. so
if you change your code

HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate("http://
est.rbma.com/content/Hagar_The_Horri ble?date=200805 30");
request .Referer="Somec rap.com";

it mite work....
Jun 27 '08 #7
On Mon, 02 Jun 2008 11:57:33 -0700, parez <ps*****@gmail. comwrote:
I tried going to
http://est.rbma.com/content/Hagar_Th...?date=20080530
and i got an image which said no referer.

so i created an html page with that image as the source and opened
it and it worked.

which means that the image server is only checking for a referrer. so
if you change your code

HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate("http://
est.rbma.com/content/Hagar_The_Horri ble?date=200805 30");
request .Referer="Somec rap.com";

it mite work....
I find it interesting that _any_ referrer is sufficient. Usually web
sites check the referrer to make sure it's actually their own web page
(prevents hijacking/embedding content in a non-hosted page).

Anyway, to the OP: I would guess that the suggestion from "parez" will in
fact solve your problem.

Pete
Jun 27 '08 #8
On Jun 2, 3:06 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Mon, 02 Jun 2008 11:57:33 -0700, parez <psaw...@gmail. comwrote:
I tried going to
http://est.rbma.com/content/Hagar_Th...?date=20080530
and i got an image which said no referer.
so i created an html page with that image as the source and opened
it and it worked.
which means that the image server is only checking for a referrer. so
if you change your code
HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate("http://
est.rbma.com/content/Hagar_The_Horri ble?date=200805 30");
request .Referer="Somec rap.com";
it mite work....

I find it interesting that _any_ referrer is sufficient. Usually web
sites check the referrer to make sure it's actually their own web page
(prevents hijacking/embedding content in a non-hosted page).

Anyway, to the OP: I would guess that the suggestion from "parez" will in
fact solve your problem.

Pete
Well.. actually i tried that again. .i got no referer image again. I
must have got a cached imaged when i ran it locally from desktop.

HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate("http://
est.rbma.com/content/Hagar_The_Horri ble?date=200805 30");

request .Referer="Somec rap.com";

so instead of somecrap.com OP (i dont know what that means) will have
to use washtingtonpost .com
Jun 27 '08 #9
On Mon, 02 Jun 2008 12:30:06 -0700, parez <ps*****@gmail. comwrote:
Well.. actually i tried that again. .i got no referer image again. I
must have got a cached imaged when i ran it locally from desktop.
Ah. That makes more sense, and is consistent with how web servers usually
do it. :)
HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate("http://
est.rbma.com/content/Hagar_The_Horri ble?date=200805 30");

request .Referer="Somec rap.com";

so instead of somecrap.com OP (i dont know what that means) will have
to use washtingtonpost .com
"OP" is "original poster". Shorthand way of writing "that guy who started
all this" :).

Anyway, yes...the program will have to set the referrer field correctly.
It may be sufficient to just use the domain name, or it may be required to
use the actual URL for the web page that would normally host the content,
depending on what the web server is doing specifically.

Personally, it's my opinion that when one starts impersonating a web page,
they are getting into a gray area with respect to content/copyright
ethics. The web server owner is clearly specifically interested in making
sure that when you look at the comic, you do so in a particular context.
When you impersonate that context, you break the implied contract with the
content producer.

From the content producer's point of view, that contract may involve
ensuring that advertising or other contextual things that they deem
important or financially necessary are included. If you as the viewer
aren't willing to abide by that contract, then you're basically saying you
don't approve of the "sale", and thus shouldn't be "buying" (that is, just
don't read the comic).

As far as I know, this is not technically illegal per se. But it
definitely seems a little "wrong" to me. From an implementation point of
view, this could be avoided by just using the WebBrowser control and
displaying the entire original page rather than just the comic. That
would also automatically fix the "referrer" issue. :)

Pete
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
12994
by: thedebugger | last post by:
Dear Friends, I am making one RSS News Reader Desktop application in c#. Where I will show the images from website. I am generating xml file on server. like http://www.zeetelevision.com/myxml.xml Problem is PictureBox1.Image = Image.FromFile("http://www.zeetelevision.com/images/today.jpg"); Its giving me error, URI path not supported..
6
8570
by: Saya | last post by:
Hello, This is a repost 'cause I haven't solve the problem: I can't use the System.Drawing class 'Image.FromStream' in the CompactFramework environment. What I've done with respect to Brendan's suggestion is as follows: Brendan, thanks for the reply! I'm a little bit further now, but not yet finished. I've come this far, see code below: Stream s =
1
11590
by: wschlichtman | last post by:
I'm attempting to retrieve a bitmap from an image field in SQL Server 2005 using Visual Studio 2005 C#. I then want to load the bitmap into a picturebox. When I run the following code, I get the error message: Parameter is no valid. Debugging shows that the Image.FromStream(ms) statement is the culprit. Anyone know what I'm doing wrong?
17
4661
by: Jan Nielsen | last post by:
Hi I would like to databind a Picturebox to a SQL Server. I have a typed Dataset "DSBoernekirken1" It has a table named "tpersoner" with a column "Photo" I of course would like to bind the image directly to tpersoner.photo using Properties (like I do with text fields), but this does not seem to be possible. Then I searched some news groups and Knowledgebase and found the following
2
3754
by: Mark | last post by:
Hello, Say I write a picture file to: 'c:\test.jpg' Then I assign this picture to a picturebox PbFoto.Image = Image.Fromfile("c:\test.jpg") Next I want the overrwrite the file test.jpg with another picture. When running, he says the file is in use when I want to overwrite it.
7
11909
by: Gary Shell | last post by:
I have a column named "PictureImage" in a SQL database defined as datatype=image. It has a Bitmap picture in it. (I verified the type by creating an Access project and a looking at the data, which access reports as "Bitmap Image".) In my VB.NET app I use the following code: Dim bytBLOBData() As Byte = Me.datasetProduct.Tables("Product").Rows(0)("PictureImage") Dim stmBLOBData As New MemoryStream(bytBLOBData)
8
10336
by: ..:: Kevin ::.. | last post by:
If I load a PictureBox image from an embedded resource within my application it works fine but if I load the same image from a file using OpenFileDialog (as an ImageStream or using the file name) the background color is not masked out. Any ideas?
4
10517
by: John Daly | last post by:
Does anyone know how to create an image (JPEG) from an HTTPResponse object? I am working on system that has a map pop up from our GIS department. I want create an image at runtime from this popup and display that image on the main page instead of opening a new window. This image will be a memory stream only, but will need to be kept from page to page, and printer if required. Any help will be much appreciated. If anyone knows of any...
3
2034
by: Brandon Arnold | last post by:
I'm having an issue that I can't quite figure out. I have a PictureBox that initially sets a picture from an embedded resource. The user clicks a listview item and if an image url is available, it sets the ImageLocation property to the url of the image and loads it. Then if the user clicks a ListView item without an image url, the default embedded image is displayed. This all works great, but if I click an item with an image url, then...
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.