PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Noms de domaine > comp.protocols.tcp-ip > GET image - http protocol
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.protocols.tcp-ip TCP and IP network protocols.

GET image - http protocol

Réponse
 
LinkBack Outils de la discussion
Vieux 26/09/2007, 12h05   #1
opexoc@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut GET image - HTTP protocol

Hello,

I have met very strange problem which is connected with HTTP protocol
and getting image from some www site.
I have written some HTTP client which is to connect to server and
execute one GET command.
I connect to www.google.pl throught my program and I use GET method to
download its background. It seems that everything is <OK>, but when I
try to open this .PNG file then every picture viewer program tell that
it doesn't know format of this file. So, I downloaded some hex editor
program to look at bytes in this file and compare this file to "the
same" image downloaded thanks to browser. It appears that generally
files are identical, but in many places I can see that bytes are
different. What is reason of such weird problem?

I hope that I write to appropriate discussion group.

Wiktor

  Réponse avec citation
Vieux 26/09/2007, 16h51   #2
GArlington
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

On 26 Sep, 12:05, ope...@gmail.com wrote:
> Hello,
>
> I have met very strange problem which is connected with HTTP protocol
> and getting image from some www site.
> I have written some HTTP client which is to connect to server and
> execute one GET command.
> I connect towww.google.plthrought my program and I use GET method to
> download its background. It seems that everything is <OK>, but when I
> try to open this .PNG file then every picture viewer program tell that
> it doesn't know format of this file. So, I downloaded some hex editor
> program to look at bytes in this file and compare this file to "the
> same" image downloaded thanks to browser. It appears that generally
> files are identical, but in many places I can see that bytes are
> different. What is reason of such weird problem?
>
> I hope that I write to appropriate discussion group.
>
> Wiktor


The reason is simple - the difference in data handling between your
client (> I have written some HTTP client which is to connect to
server and execute one GET command) and default data handling of the
browser. I am guessing your client is adding some data in the end of
every packet it gets from the connection...

  Réponse avec citation
Vieux 26/09/2007, 17h12   #3
David Tiktin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut GET image - http protocol

On 26 Sep 2007, opexoc@gmail.com wrote:

> I have met very strange problem which is connected with HTTP
> protocol and getting image from some www site.
> I have written some HTTP client which is to connect to server and
> execute one GET command.
> I connect to www.google.pl throught my program and I use GET
> method to download its background. It seems that everything is
> <OK>, but when I try to open this .PNG file then every picture
> viewer program tell that it doesn't know format of this file. So,
> I downloaded some hex editor program to look at bytes in this file
> and compare this file to "the same" image downloaded thanks to
> browser. It appears that generally files are identical, but in
> many places I can see that bytes are different. What is reason of
> such weird problem?


When your program writes the file to disk, do you by chance open the
file in text mode (in C, fopen(filename, "w")) instead of binary mode
(fopen(filename, "wb"))? This will likely result in a few altered
bytes in the file on many systems. Make sure you're opening the file
in binary mode.

> I hope that I write to appropriate discussion group.


Close enough ;-)

Dave

--
D.a.v.i.d T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m
  Réponse avec citation
Vieux 26/09/2007, 20h59   #4
opexoc@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

On 26 Wrz, 18:12, David Tiktin <dtik...@nospam.totally-bogus.com>
wrote:

> When your program writes the file to disk, do you by chance open the
> file in text mode (in C, fopen(filename, "w")) instead of binary mode
> (fopen(filename, "wb"))? This will likely result in a few altered
> bytes in the file on many systems. Make sure you're opening the file
> in binary mode.


Hmm... I open file this way:

ofstream out;
out.open("myfile.txt", ios:ut);

Can it be wrong way to open file?

Wiktor

  Réponse avec citation
Vieux 26/09/2007, 21h02   #5
opexoc@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

On 26 Wrz, 17:51, GArlington <garling...@tiscali.co.uk> wrote:

> The reason is simple - the difference in data handling between your
> client (> I have written some HTTP client which is to connect to
> server and execute one GET command) and default data handling of the
> browser. I am guessing your client is adding some data in the end of
> every packet it gets from the connection...


This reason could be true, but I don't think so.Code which is to
receive data looks:

std::string Socket::ReceiveBytes() {
std::string ret;
char buf[1024];

while (1) {
u_long arg = 0;
if (ioctlsocket(s_, FIONREAD, &arg) != 0)
break;

if (arg == 0)
break;

if (arg > 1024) arg = 1024;

int rv = recv (s_, buf, arg, 0);
if (rv <= 0) break;

std::string t;

t.assign (buf, rv);
ret += t;
}

return ret;
}

and that's all.

Wiktor


  Réponse avec citation
Vieux 26/09/2007, 22h55   #6
Frank Swarbrick
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

>>> On 9/26/2007 at 1:59 PM, in message
<1190836789.443616.287990@r29g2000hsg.googlegroups .com>, <opexoc@gmail.com>
wrote:
> On 26 Wrz, 18:12, David Tiktin <dtik...@nospam.totally-bogus.com>
> wrote:
>
>> When your program writes the file to disk, do you by chance open the
>> file in text mode (in C, fopen(filename, "w")) instead of binary mode
>> (fopen(filename, "wb"))? This will likely result in a few altered
>> bytes in the file on many systems. Make sure you're opening the file
>> in binary mode.

>
> Hmm... I open file this way:
>
> ofstream out;
> out.open("myfile.txt", ios:ut);
>
> Can it be wrong way to open file?


I don't (generally) use C++, but doing a Google search it looks like you
might want to change the open to:
out.open("myfile.txt", ios:binary | ios:ut);

I assume it's not actually, in fact, a text file, since previously you
mentioned it was a PNG file.

  Réponse avec citation
Vieux 27/09/2007, 10h30   #7
opexoc@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

On 26 Wrz, 23:55, "Frank Swarbrick" <Frank.Swarbr...@efirstbank.com>
wrote:

> I don't (generally) use C++, but doing a Google search it looks like you
> might want to change the open to:
> out.open("myfile.txt", ios:binary | ios:ut);
>
> I assume it's not actually, in fact, a text file, since previously you
> mentioned it was a PNG file.


It did , but not completely. Now ( and this is very weird ) every
byte in myfile.txt which has 20h value in true file downloaded by
browser in exactly the same location is 00h byte. Is it any good
explanation for that?

Wiktor

  Réponse avec citation
Vieux 27/09/2007, 17h26   #8
David Tiktin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

On 27 Sep 2007, opexoc@gmail.com wrote:

> On 26 Wrz, 23:55, "Frank Swarbrick"
> <Frank.Swarbr...@efirstbank.com> wrote:
>
>> I don't (generally) use C++, but doing a Google search it looks
>> like you might want to change the open to:
>> out.open("myfile.txt", ios:binary | ios:ut);
>>
>> I assume it's not actually, in fact, a text file, since
>> previously you mentioned it was a PNG file.

>
> It did , but not completely. Now ( and this is very weird )
> every byte in myfile.txt which has 20h value in true file
> downloaded by browser in exactly the same location is 00h byte. Is
> it any good explanation for that?


You originally posted about a problem with a .png file. Was that
solved by Frank's suggestion that you add ios:binary to the flags
when you open the file? Can you now transfer .png files correctly?

You switched to talking about a .txt file, which I take to mean an
ASCII text file. C and C++ use 0x00 (NUL) as the end-of-string
character and 0x20 is the ASCII space character, so the values that
are being converted don't seem just random, and could be related to
handling the data as text elsewhere in your program.

Have you done a capture of a download session using ethereal or
wireshark to verify that the data coming over the line actually has
the values you expect? How are you verifying the contents of the
file? Why not hex dump the data as you receive it and see what
you're actually reading off the socket?

Dave

--
D.a.v.i.d T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m
  Réponse avec citation
Vieux 27/09/2007, 19h07   #9
opexoc@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

On 27 Wrz, 18:26, David Tiktin <dtik...@nospam.totally-bogus.com>
wrote:

> You switched to talking about a .txt file, which I take to mean an
> ASCII text file. C and C++ use 0x00 (NUL) as the end-of-string
> character and 0x20 is the ASCII space character, so the values that
> are being converted don't seem just random, and could be related to
> handling the data as text elsewhere in your program.


Ok. Problem have been solved. One thing should be changed - the name
of file and that's it.

out.open("myfile",ios::binary | ios:ut);
No myfile.txt, but just myfile.

Thanks!

Wiktor




  Réponse avec citation
Vieux 28/09/2007, 01h18   #10
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

In article <1190916472.243764.224160@k79g2000hse.googlegroups .com>,
opexoc@gmail.com wrote:

> On 27 Wrz, 18:26, David Tiktin <dtik...@nospam.totally-bogus.com>
> wrote:
>
> > You switched to talking about a .txt file, which I take to mean an
> > ASCII text file. C and C++ use 0x00 (NUL) as the end-of-string
> > character and 0x20 is the ASCII space character, so the values that
> > are being converted don't seem just random, and could be related to
> > handling the data as text elsewhere in your program.

>
> Ok. Problem have been solved. One thing should be changed - the name
> of file and that's it.
>
> out.open("myfile",ios::binary | ios:ut);
> No myfile.txt, but just myfile.


If the filename suffix changes the behavior of your C++ library, I'd
complain to your C++ vendor.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 28/09/2007, 09h03   #11
opexoc@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: GET image - HTTP protocol

On 28 Wrz, 02:18, Barry Margolin <bar...@alum.mit.edu> wrote:

> If the filename suffix changes the behavior of your C++ library, I'd
> complain to your C++ vendor.


That's right. But, I can't change anything.

Wiktor



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h01.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,21131 seconds with 19 queries