Notes
Gets content from a url (http fetch, http get). It is the simplest way to grab web page content from an external website.
If the page you request sends you a redirect error code such as 301 or 302, the HttpGet function will automatically try and find the correct page and send the content of the final arrival page after any redirects.
If you want to set the User Agent, use the function HttpGet1.
Error codes
If there was an error found, the function returns the strings:
- '-1 err' if address from inet resolve was invalid
- '-2 err' if could not connect to socket
- a string starting with '-3 err: ' plus extra info if the website did not return a 200, 301, 302, or 303 error
SSL/HTTPS
At current time of writing the HTTP.PAS unit is not capable of getting SSL/HTTPS web pages. You can try cURL or Synapse if you need that functionality. SSL/HTTPS may be a feature added to the HTTP.PAS unit in the future, however we are wondering if maybe the HTTP.PAS unit is just reinventing cURL since it is very similar (although http.pas is written in Pascal whereas cURL is written in C). You can send us your thoughts on the
mailing list about the future of the http.pas unit.
Developer note
As of version 1.6.0.0 this function has not been optimized.. it grabs the page char by char. In the future it will be optimized to be faster using larger socket chunks.
Example
var
tmp: string;
begin
webwrite('Someone's web page is below');
webwrite('<hr>');
// you should do a <FRAME> here
tmp:= HttpGet('http://yahoo.com');
webwrite(tmp);
// you should do a closing </FRAME> here
// otherwise strip the <HTML> and <HEAD> from the web page you stole, and integrate
// it into your content
end.
Tips
No httpconnect or httpclose is required before making a call to this function. It does that internally for you.