Sign in Join

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

Mailing lists / fpc-pascal / 2005-11

Download file

9 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

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

Unknown author

Question:
I would like to download a file via HTTP, how can I achieve that in a platform independent way? What components to use and is there some code suited for dummy's available.

Darius

Reply by email

Paul Davidson
to Unknown author

The silly answer. Construct an HTTP message according to IETF/W3C rules.

Better answer. Assuming you have a socket connection open, the following should be included
in your message:

HTTP/1.0 200<crlf>
Connection: Close<crlf>
Content-length:<number of byte in Content: below, as ASCII string> Content-type:<text/ascii, or something similar><crlf> MIME-version:1.0<crlf>
<crlf>
<content>

The above should be in single string.
<crlf> means carriage return/line feed, or ASCII chars 10 and 13. Content-type is important. text/ASCII will work in most situations. Otherwise see MIME standards at http://www.ietf.org for more details. Please note that is extra <crlf> after text headers. This is to indicate that what follows is the data you want to transmit.

There are many other fields that can be added, depending on who is at other end of connection, but the ones above should work in most situation. This is NOT ACID compliant.

See http://www.w3.org/Protocols/ for more details on HTTP.

Show quoted text 12 lines
Question: I would like to download a file via HTTP, how can I achieve that in a platform independent way? What components to use and is there some code suited for dummy's available. Darius _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

P Davidson
Corax Networks Inc.
http://CoraxNetworks.com

Reply by email

Paul Davidson
to L505

It does not work as is on Mac, but then, most people don't care. *cry*

L505 wrote 15 lines
> Question: > I would like to download a file via HTTP, how can I achieve that in a Synapse is nice.. Note: It is not 100 percent platform independent. (works on Linux and Windows possibly other operating systems.) _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

P Davidson
Corax Networks Inc.
http://CoraxNetworks.com

IMPORTANT NOTICE: This message is intended only for the use of the individual or entity to which it is addressed. The message may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify Corax Networks immediately by email at Thank you.

Reply by email

Jeff Pohlmeyer
I would like to download a file via HTTP, how can I achieve that in a platform independent way? What components to use and is there some code suited for dummy's available.

If you don't mind using an external DLL, CurlPas is quite simple, and works on Linux, Windows, and possibly even Mac...

========================
program simple;
uses curl_obj;
var
  Curl:TCurl;
begin
  Curl:=TCurl.Create(nil);
  Curl.URL:='http://www.freepascal.org/index.html';
  Curl.OutputFile:='fpc.htm';
  if ( not Curl.Perform ) then WriteLn(Curl.ErrorString);
  Curl.Free;
end;
=====================

And that's all there is to it! The library can automatically follow any redirects, deal with cookies, handle https and ftp downloads, etc, etc, etc...

For more info, see:
http://curlpas.sourceforge.net/
http://curl.haxx.se/libcurl/

- Jeff

Reply by email

Tony Pelton
to Jeff Pohlmeyer
Jeff Pohlmeyer wrote
If you don't mind using an external DLL, CurlPas is quite simple,

and presumably, if you are crafty, and licensing supports it, you could link the curlpas runtime statically such that you don't need the lib.

Tony

Reply by email

L
to Paul Davidson: It does not work as is on Mac, but then, most people don't care. *cry* P Davidson Corax…
It does not work as is on Mac, but then, most people don't care. *cry*

<rant flamebait offtopic>
I would consider a Mac if they didn't weld them shut like those iMacs. Talk about closed source hardware.

Of course for every complaint I make someone will come back with "but you can buy Macs with a tower case and a separate monitor". That's not the point. The point is that the majority of them out there are welded shut (if I were to buy a used one for example).

I'm quite interested in Mac's since they have a Pascal history.

But they sure ruined it with Jobs' colorful Pascal poster and colorful welded shut iMacs. Otherwise, I would have researched them further. I've also had quite a few crashes when setting up a Mac for networking, so the "no bugs on Macs" pick-up line doesn't hold out. I would never ever claim that XYZ computer has less bugs than ABC computer if I was a marketing company. That's poor marketing and just asking to be proven wrong.
</rant flamebait offtopic>

Reply by email

Paul Davidson
to L

Nice rant :)

Show quoted text 40 lines
> It does not work as is on Mac, but then, most people don't care. > *cry* > <rant flamebait offtopic> I would consider a Mac if they didn't weld them shut like those iMacs. Talk about closed source hardware. Of course for every complaint I make someone will come back with "but you can buy Macs with a tower case and a separate monitor". That's not the point. The point is that the majority of them out there are welded shut (if I were to buy a used one for example). I'm quite interested in Mac's since they have a Pascal history. But they sure ruined it with Jobs' colorful Pascal poster and colorful welded shut iMacs. Otherwise, I would have researched them further. I've also had quite a few crashes when setting up a Mac for networking, so the "no bugs on Macs" pick-up line doesn't hold out. I would never ever claim that XYZ computer has less bugs than ABC computer if I was a marketing company. That's poor marketing and just asking to be proven wrong. </rant flamebait offtopic> _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

P Davidson
Corax Networks Inc.
http://CoraxNetworks.com

IMPORTANT NOTICE: This message is intended only for the use of the individual or entity to which it is addressed. The message may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify Corax Networks immediately by email at Thank you.

Reply by email