Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-01

Get binary (byte by byte) from a HTTP host

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hi folks,

I'm tryng to download byte by byte from a binary in a HTTP host, but synapse put the header informations in my binary, e.g.:

My original binary content:
0AAAAAAAAAAAAAAAAAAA
1AAAAAAAAAAAAAAAAAAA
2AAAAAAAAAAAAAAAAAAA

Synapse content:
*HTTP/1.1 200 OK
Date: Mon, 17 Jan 2011 15:40:57 GMT
Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
Last-Modified: Mon, 17 Jan 2011 15:38:09 GMT
ETag: "d000000054b36-40-49a0c922bb965"
Accept-Ranges: bytes
Content-Length: 64
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain*

0AAAAAAAAAAAAAAAAAAA
1AAAAAAAAAAAAAAAAAAA
2AAAAAAAAAAAAAAAAAAA

How I get only 0AAAAAAAAAAAAAAAAAAA, 1AAAAAAAAAAAAAAAAAAA, 2AAAAAAAAAAAAAAAAAAA... to save in my binary?

Thanks, and excuse me for my poor english. ;)

PS. Simple sample to reproduce 'error' in attached.

*Silvio Cl?cio* *Blog.* blog.silvioprog.com.br *Twitter.* twitter.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110117/19c9cd21/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: how.zip Type: application/zip Size: 2773 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110117/19c9cd21/attachment-0001.zip>

Reply by email

ik
to silvioprog

Try to use FHTTPSend.Document

Please note that it's a stream.

Ido
LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il

2011/1/17 silvioprog

Show quoted text 47 lines
Hi folks, I'm tryng to download byte by byte from a binary in a HTTP host, but synapse put the header informations in my binary, e.g.: My original binary content: 0AAAAAAAAAAAAAAAAAAA 1AAAAAAAAAAAAAAAAAAA 2AAAAAAAAAAAAAAAAAAA Synapse content: *HTTP/1.1 200 OK Date: Mon, 17 Jan 2011 15:40:57 GMT Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 Last-Modified: Mon, 17 Jan 2011 15:38:09 GMT ETag: "d000000054b36-40-49a0c922bb965" Accept-Ranges: bytes Content-Length: 64 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/plain* 0AAAAAAAAAAAAAAAAAAA 1AAAAAAAAAAAAAAAAAAA 2AAAAAAAAAAAAAAAAAAA How I get only 0AAAAAAAAAAAAAAAAAAA, 1AAAAAAAAAAAAAAAAAAA, 2AAAAAAAAAAAAAAAAAAA... to save in my binary? Thanks, and excuse me for my poor english. ;) PS. Simple sample to reproduce 'error' in attached. -- *Silvio Cl?cio* *Blog.* blog.silvioprog.com.br *Twitter.* twitter.com/silvioprog -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110117/20d07862/attachment.html>

Reply by email

silvioprog
to ik

Hi Ido,

I tryed with Document, but without sucess. :(

My second simple demo (not works) with Document in attached.

PS. My binary can be TXT, EXE, XML etc.

2011/1/17 ik

Show quoted text 10 lines
Try to use FHTTPSend.Document Please note that it's a stream. Ido LINESIP - Opening the source for communication http://www.linesip.com http://www.linesip.co.il --

*Silvio Cl?cio*
*Blog.* blog.silvioprog.com.br
*Twitter.* twitter.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110117/7ff21cbb/attachment-0001.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: how.zip
Type: application/zip
Size: 2749 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110117/7ff21cbb/attachment-0001.zip> -------------- next part --------------
A non-text attachment was scrubbed...
Name: test.bin
Type: application/octet-stream
Size: 968 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110117/7ff21cbb/attachment-0001.bin>

Reply by email

Sven Barth
to silvioprog
silvioprog wrote 13 lines
Hi Ido, I tryed with Document, but without sucess. :( My second simple demo (not works) with Document in attached. PS. My binary can be TXT, EXE, XML etc. 2011/1/17 ik < <mailto:>> Try to use FHTTPSend.Document Please note that it's a stream.

HTTP headers *always* end after an empty line. So you could scan for two newlines after each other (I don't know whether you must only look for LineFeed or CarriageReturn or both).

Regards,
Sven

Reply by email

ik
to silvioprog: I tryed with Document, but without sucess. :( My second simple demo (not works) with…

2011/1/17 silvioprog

Hi Ido, I tryed with Document, but without sucess. :(

You must rewind the Stream before copy it, because the position is at the end of the stream, so it can not copy empty data. I guess you have an exception on it.

Show quoted text 28 lines
My second simple demo (not works) with Document in attached. PS. My binary can be TXT, EXE, XML etc. 2011/1/17 ik Try to use FHTTPSend.Document > > Please note that it's a stream. > > Ido > LINESIP - Opening the source for communication > http://www.linesip.com > http://www.linesip.co.il > > -- *Silvio Cl?cio* *Blog.* blog.silvioprog.com.br *Twitter.* twitter.com/silvioprog -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Ido
LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110117/c05fc682/attachment.html>

Reply by email

silvioprog
to Sven Barth: HTTP headers *always* end after an empty line. So you could scan for two newlines after…

Hi Sven,

Always an empty line... this is a very good information. ;)

Hm..., a reply from the synapse list:

(...)
2011/1/17 Lukas Gebauer <gebylist at ...>
Just courious - where you are reading THttpSend.Document with readed binary datas? And why you are saving to your stream values from OnMonitor event? This event is designed for monitoring socket traffic, not for reading datas.

Lukas Gebauer. http://synapse.ararat.cz/ - Ararat Synapse - TCP/IP Lib. http://geoget.ararat.cz/ - Geocaching solution (....) If not OnMonitor, what I use? x( 2011/1/17 Sven Barth > > HTTP headers *always* end after an empty line. So you could scan for two > newlines after each other (I don't know whether you must only look for > LineFeed or CarriageReturn or both). > > Regards, > Sven > -- *Silvio Cl?cio* *Cel.* (15) 9122-7768 *Blog.* blog.silvioprog.com.br *Twitter.* twitter.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110117/37e235fc/attachment-0001.html>

Reply by email

silvioprog
to ik: 2011/1/17 silvioprog You must rewind the Stream before copy it, because the position is…

Not works, Document property always is empty in OnMonitor event. x(

Hm..., I think isn't possible resume download with Synapse, I tryed all but without sucess.

2011/1/17 ik

Show quoted text 9 lines
You must rewind the Stream before copy it, because the position is at the end of the stream, so it can not copy empty data. I guess you have an exception on it. Ido LINESIP - Opening the source for communication http://www.linesip.com http://www.linesip.co.il
*Silvio Cl?cio* *Cel.* (15) 9122-7768 *Blog.* blog.silvioprog.com.br *Twitter.* twitter.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110118/5927f975/attachment.html>

Reply by email

José Mejuto
to silvioprog

Hello Lazarus-List,

Tuesday, January 18, 2011, 4:13:13 AM, you wrote:

s> Not works, Document property always is empty in OnMonitor event. x(

You can not access Document from OnMonitor, you can only access Socked properties/status.

Synapse is blocking, so :

1) HTTPSend prepare headers.
2) HTTPSend GET
3) HTTPSend access document.

Or in your code:
------------------------------------------------------
procedure TMainForm.StartButtonClick(Sender: TObject);
begin
  if FileExistsUTF8(CFile) then
    FFileStream := TFileStream.Create(CFile, fmOpenReadWrite)
  else
    FFileStream := TFileStream.Create(CFile, fmCreate);
  try
    FHTTPSend.Sock.MaxRecvBandwidth := 50;
    FHTTPSend.Clear;
    FHTTPSend.RangeEnd := FFileStream.Size;
    FFileStream.Position := FFileStream.Size;
    FHTTPSend.HTTPMethod('GET', CURL);
    //Now you can acess Document
    FFileStream.CopyFrom(FHTTPSend.Document, FHTTPSend.Document.Size);
  finally
    FFileStream.Free;
  end;
end;
procedure TMainForm.OnMonitor(Sender: TObject; Writing: Boolean;
  const Buffer: Pointer; Len: Integer);
begin
  //Nothing...
  //FHHTPSend information at this point is undefined.
end;
--------------------------------------------------------

s> Hm..., I think isn't possible resume download with Synapse, I tryed all but s> without sucess.

What's the problem ? Paste headers sent and received headers. Resuming is not supported by all web servers.

Best regards, Jos?

Reply by email

silvioprog
to José Mejuto

Thanks Jos?. I'm implementing another simple demo, after I finish I share here.

Thanks to all.

2011/1/18 Jos? Mejuto

Show quoted text 55 lines
Hello Lazarus-List, Tuesday, January 18, 2011, 4:13:13 AM, you wrote: s> Not works, Document property always is empty in OnMonitor event. x( You can not access Document from OnMonitor, you can only access Socked properties/status. Synapse is blocking, so : 1) HTTPSend prepare headers. 2) HTTPSend GET 3) HTTPSend access document. Or in your code: ------------------------------------------------------ procedure TMainForm.StartButtonClick(Sender: TObject); begin if FileExistsUTF8(CFile) then FFileStream := TFileStream.Create(CFile, fmOpenReadWrite) else FFileStream := TFileStream.Create(CFile, fmCreate); try FHTTPSend.Sock.MaxRecvBandwidth := 50; FHTTPSend.Clear; FHTTPSend.RangeEnd := FFileStream.Size; FFileStream.Position := FFileStream.Size; FHTTPSend.HTTPMethod('GET', CURL); //Now you can acess Document FFileStream.CopyFrom(FHTTPSend.Document, FHTTPSend.Document.Size); finally FFileStream.Free; end; end; procedure TMainForm.OnMonitor(Sender: TObject; Writing: Boolean; const Buffer: Pointer; Len: Integer); begin //Nothing... //FHHTPSend information at this point is undefined. end; -------------------------------------------------------- s> Hm..., I think isn't possible resume download with Synapse, I tryed all but s> without sucess. What's the problem ? Paste headers sent and received headers. Resuming is not supported by all web servers. -- Best regards, Jos?
*Silvio Cl?cio* *Cel.* (15) 9122-7768 *Blog.* blog.silvioprog.com.br *Twitter.* twitter.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110119/93bfbdd7/attachment.html>

Reply by email

silvioprog
to José Mejuto: s> Not works, Document property always is empty in OnMonitor event. x( You can not access…

Hi friends ;)

Problem solved, solution in attached.

Thanks...Thanks...Thanks... \o\o\o
/o/o/o/
\oXoX/

:}D

*Silvio Cl?cio* *Blog.* blog.silvioprog.com.br *Twitter.* twitter.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110119/228cc93b/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: SimpleDemo.zip Type: application/zip Size: 4546 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110119/228cc93b/attachment.zip>

Reply by email