HTTPPostLoad

Internet
Aptilis 2

HTTPPostLoad(url,headers[],formFields[])

Although LoadFile allows you to load documents from web servers, you cannot specify the HTTP headers of your request.
HTTPLoad allows you to do so, by specifying a key based array of name/value pairs:

h["Accept"] = "*.*" $
h["Accept-Language"] = "en-us" $
h["User-Agent"] = "Aptilis/2.0" $
h["Host"] = _Host + ":80" $
h["Connection"] = "Close" $
h["Cache-Control"] = "no-cache" $
and so on...

HTTPPostLoad will use the post method, and add the variables you specified to the request. To the web server, your request will look exactly as if it were coming from a web browser.

formfield["name"] = "teebo" $
formfield["creditCardNumber"] = "12345678910" $
page = httpPostLoad("http://www.someserver.com/cgi-bin/order.cgi", h[], formfield[]) $

Important note:
Even if you specify a content-length and a content-type in your request, they will be overwritten by Aptilis to reflect the appropriate content-type and length of your request as per the POST method.

Specifying a Url
Here is an http:// Url: "http://www.cnn.com/"

You can use IP numbers and port numbers as well to override the default ports for http:// (80), such as:
"http://www.xnn.org:8080/news/secret.html"

In the case of web pages, the document returned contains the page itself and its header. The end of the header is after the occurrence of the header delimiter: "\n\n", or possibly "\r\n\r\n". I usually remove the "\r" 's anyway:

file = replace(file$, "\r", "") $
One of the applications of this is to be able to see the source of pages that might not be kept by your browser, and allow you to see how 'they do it'. You can also 'nick' the content of different pages and re-arrange them in a page of your own. But that's quite naughty. :-)

Return Value:
The whole file if everything was OK.
An empty string in case of error and the _errno variable contains more details about the error.

See also: HTTPLoad, loadPostFile, loadFile, saveFile.