HTTP_GET()
Syntax
Result as P = HTTP_GET( URL as C [, Cookie as C [, Port as N [, Timeout as N [, Show_Before_Send as L [, Validate_SSL_Certificate as L ]]]]] )
|
Argument |
Description |
||
|
Result |
A dot variable containing the server's response. |
||
|
Argument |
Type |
Description | |
|
.error_text |
C |
The error message, if any. | |
|
.error_code |
N |
The error number, if any. | |
|
.headers |
C |
Response headers. | |
|
.body |
B |
Response body. | |
|
URL |
The URL of the page to retrieve. |
||
|
Cookie |
Optional. Default = "". Cookie data. Limited to 8 MBytes. |
||
|
Port |
Optional. Default = -1. The port to use. |
||
|
Timeout |
Optional. Default = 8000 milliseconds. The number of milliseconds to wait before timing out. |
||
|
Show_Before_Send |
Optional. Default = .F.. When .T., displays the request before being sent. Useful for debugging. |
||
|
Validate_SSL_Certificate |
Optional. Default = .T.. If the specified URL starts with "https://", this flag controls whether or not the certificate offered by the server will be validated. If set to .T., the request will always fail. If set to .F., the request may succeed, but the server's identity is not guaranteed. |
||
Description
The HTTP_GET() function downloads from a URL using HTTP/1.1 GET. The function supports cookies and returns a pointer with the parsed response from the server.
Note : When the server
responds with a 302 code, HTTP_GET() does not automatically use the new
URL. The developer needs to examine result.parsed_headers.status_code,
then if appropriate, try the URL provided in result.parsed_headers.location.
The parsed response will include several elements, including the following.
|
Argument |
Example |
| Result.parsed_headers.ContentType | "text/html" |
| Result.parsed_headers.ContentLength | "12541" |
| Result.parsed_headers.Date | "Wed, 30 Jun 2004 14:36:12 GMT" |
| Result.parsed_headers.Server | "Microsoft-IIS/5.0" |
Note : A HTTP GET is
different from a HTTP POST in two significant ways. Some devices may restrict
the total length of a URL to 128 characters, which may trim the arguments
appended by a GET command. There is no such restriction with POST commands.
You may save (bookmark) and refresh URLs formatted through a HTTP GET
command. The arguments sent by a HTTP POST command are not saved in a
bookmark.
Supported By
Alpha Five Version 6 and Above
Examples
The following example follows a redirect.
|
dim url as C = "support.alphasoftware.com" dim result as P result = http_fetch(url) if (result.parsed_headers.status_code = 302) then result = http_get(result.parsed_headers.Location) ... end if |
Retrieve the Alpha Software home page.
|
dim alpha as P alpha = http_get("http://www.alphasoftware.com/") a5_show_html(alpha.body) |
Search Google.
|
dim search_term as C dim google as P search_term = ui_get_text("Search for...","What are you looking for?") google = http_get("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=" + urlencode(search_term)) a5_show_html(google.body) |
Retrieve RSS text from Slashdot.org.
|
dim rss as P rss = http_get("http://slashdot.org/index.rss") if .not. eval_valid("rss.body") ui_msg_box("Error","The RSS file was not downloaded from the server.",UI_STOP_SYMBOL) else dim num_items as N num_items = count_textblocks(rss.body,"<item","</item>") dim item[num_items] as P dim i as N dim this_item as C for i = 1 to num_items this_item = extract_string(rss.body,"<item","</item>",i,.t.) item[i].title = extract_string(this_item,"<title>","</title>") item[i].link = extract_string(this_item,"<link>","</link>") item[i].description = extract_string(this_item, "<description>", "</description>") item[i].creator = extract_string(this_item, "<dc:creator>", "</dc:creator>") item[i].subject = extract_string(this_item, "<dc:subject>", "</dc:subject>") item[i].date = extract_string(this_item, "<dc:date>", "</dc:date>") item[i].section = extract_string(this_item, "<slash:section>", "</slash:section>") item[i].department = extract_string(this_item, "<slash:department>", "</slash:department>") item[i].comments = extract_string(this_item, "<slash:comments>", "</slash:comments>") item[i].hitparade = extract_string(this_item, "<slash:hitparade>", "</slash:hitparade>") next i 'now do something with this, like put it into a table or build an output file. a5_show_variable(property_to_string(item)) end if |
See Also