Utility functions to handle http requests. More...
Go to the source code of this file.
Enumerations | |
enum | MimeTypes { MIME_HTM = &b0000000000000, MIME_TXT = &b0000000000010, MIME_BMP = &b0000000000100, MIME_GIF = &b0000000001000, MIME_JPG = &b0000000010000, MIME_PNG = &b0000000100000, MIME_TIF = &b0000001000000, MIME_WAV = &b0000010000000, MIME_MP3 = &b0000100000000, MIME_OGG = &b0001000000000, MIME_PDF = &b0010000000000, MIME_ZIP = &b0100000000000, MIME_GZ = &b1000000000000 } |
Functions | |
FUNCTION_AS_STRING | MimeType (BYVAL_AS_MimeTypes Typ) |
Create a text version of the mime type bit mask. More... | |
FUNCTION_AS_STRING | urlEncode (BYREF_AS_STRING Url) |
Encode an URL text. More... | |
FUNCTION_AS_STRING | urlDecode (BYREF_AS_STRING Url) |
Decode an URL text. More... | |
FUNCTION_AS_STRING | httpGetReq (BYREF_AS_STRING Host, BYREF_AS_STRING Targ, BYVAL_AS_MimeTypes Mime=MIME_HTM OR MIME_TXT) |
Create a HTTP GET request. More... | |
FUNCTION_AS_STRING | httpHeadReq (BYREF_AS_STRING Host, BYREF_AS_STRING Targ, BYVAL_AS_MimeTypes Mime=MIME_HTM OR MIME_TXT) |
Create a HTTP HEAD request. More... | |
FUNCTION_AS_STRING | httpPostReq (BYREF_AS_STRING Host, BYREF_AS_STRING Targ, BYREF_AS_STRING Query, BYVAL_AS_INTEGER Refer=1) |
Create a HTTP POST request. More... | |
FUNCTION_AS_STRING | httpPutReq (BYREF_AS_STRING Host, BYREF_AS_STRING Targ, BYREF_AS_STRING Content="") |
Create a HTTP HEAD request. More... | |
FUNCTION_AS_CONST_ZSTRING_CONST_PTR | httpLoad (BYREF_AS_STRING Res, BYREF_AS_STRING Adr, BYVAL_AS_MimeTypes Mim=MIME_HTM OR MIME_TXT, BYVAL_AS_USHORT Port=80, BYVAL_AS_SHORT Mo=&b10) |
Load a file over network via http protocol. More... | |
Variables | |
const STRING | LINEEND = !"\r\n" |
The line end characters. More... | |
const STRING | HEADEREND = !"\r\n\r\n" |
The end of header characters. More... | |
Utility functions to handle http requests.
This file contains
Copyright (C) LGPLv2.1, see ReadMe.md for details.
Definition in file nettobac_http.bas.
enum MimeTypes |
Definition at line 20 of file nettobac_http.bas.
FUNCTION_AS_STRING MimeType | ( | BYVAL_AS_MimeTypes | Typ | ) |
Create a text version of the mime type bit mask.
Typ | the bitmask containing the type bits (see enumerator MimeTypes) |
;
separated)Mime types get handled as a bit mask at module level, for better readability. This function translate the bit mask in to a STRING representation.
Definition at line 47 of file nettobac_http.bas.
FUNCTION_AS_STRING urlEncode | ( | BYREF_AS_STRING | Url | ) |
Encode an URL text.
Url | the URL text |
Encode special characters in an URL. Normal characters are
_
(underscore), /
(slash)All other characters get replaced by their %<hexval>
representation.
Definition at line 81 of file nettobac_http.bas.
FUNCTION_AS_STRING urlDecode | ( | BYREF_AS_STRING | Url | ) |
Decode an URL text.
Url | the encoded URL text |
Decode special characters in an URL. The %<hexval>
representations get resolved in to the related characters.
Definition at line 104 of file nettobac_http.bas.
FUNCTION_AS_STRING httpGetReq | ( | BYREF_AS_STRING | Host, |
BYREF_AS_STRING | Targ, | ||
BYVAL_AS_MimeTypes | Mime = MIME_HTM OR MIME_TXT |
||
) |
Create a HTTP GET request.
Host | the host adress (ie. "domain.com" ) |
Targ | the path to search for (ie. "img/test.jpg" ) |
Mime | the mime type (ie. MIME_JPG , see MimeTypes) |
Requests a representation of the specified resource.
Definition at line 126 of file nettobac_http.bas.
FUNCTION_AS_STRING httpHeadReq | ( | BYREF_AS_STRING | Host, |
BYREF_AS_STRING | Targ, | ||
BYVAL_AS_MimeTypes | Mime = MIME_HTM OR MIME_TXT |
||
) |
Create a HTTP HEAD request.
Host | the host adress (ie. "domain.com" ) |
Targ | the path to search for (ie. "html/index.html" ) |
Mime | the mime type (ie. MIME_HTM , see MimeTypes) |
Asks for the response identical to the one that would correspond to a GET request, but without the response body. It's possible to extract the content length and Mime type from it.
Definition at line 146 of file nettobac_http.bas.
FUNCTION_AS_STRING httpPostReq | ( | BYREF_AS_STRING | Host, |
BYREF_AS_STRING | Targ, | ||
BYREF_AS_STRING | Query, | ||
BYVAL_AS_INTEGER | Refer = 1 |
||
) |
Create a HTTP POST request.
Host | the host adress (ie. "domain.com" ) |
Targ | the path to search for (ie. "data/script.php" ) |
Query | (ie. "key1=value&key2=value" ) |
Refer | if a Referer: should get added |
Requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI.
Definition at line 166 of file nettobac_http.bas.
FUNCTION_AS_STRING httpPutReq | ( | BYREF_AS_STRING | Host, |
BYREF_AS_STRING | Targ, | ||
BYREF_AS_STRING | Content = "" |
||
) |
Create a HTTP HEAD request.
Host | the host adress (ie. "domain.com" ) |
Targ | the path to search for (ie. "data/test.txt" ) |
Content | any content (defaults to "" ) |
Requests that the enclosed entity be stored under the supplied URI.
Definition at line 188 of file nettobac_http.bas.
FUNCTION_AS_CONST_ZSTRING_CONST_PTR httpLoad | ( | BYREF_AS_STRING | Res, |
BYREF_AS_STRING | Adr, | ||
BYVAL_AS_MimeTypes | Mim = MIME_HTM OR MIME_TXT , |
||
BYVAL_AS_USHORT | Port = 80 , |
||
BYVAL_AS_SHORT | Mo = &b10 |
||
) |
Load a file over network via http protocol.
Res | a STRING variable to append the result |
Adr | the address of the target (ie. freebasic.net/index.html ) |
Mim | the mime type (see enumerators MimeTypes) |
Port | The port number to use (defaults to 80) |
Mo | the modus which data the result variable Res should contain |
This function loads a file over a network connection. It tries to
An error check gets done after each step. In case of an error the function breaks and the error text gets returned. Otherwise the return value 0 (zero) indicates successful operation.
Res
may contains data, the function can report an error (ie. when the connection gets lost during transfer). It's recommended to check .Errr
always.200 OK
it gets extracted from the result variable Res
(only data get returned). In order to receive the header (unchecked) as well, set bit 0 in the modus parameter (Mo OR= &b1
).Res
. In order to reset the result STRING (Res = ""
) before operaion, set bit 1 in the modus parameter (Mo OR= &b10
).Definition at line 233 of file nettobac_http.bas.
const STRING LINEEND = !"\r\n" |
The line end characters.
Definition at line 17 of file nettobac_http.bas.
const STRING HEADEREND = !"\r\n\r\n" |
The end of header characters.
Definition at line 18 of file nettobac_http.bas.