http
httpobj=new("http"[,url$])
The http object provides access to HTTP servers, more commonly known as web servers. HTTP is the protocol used by web browsers to communicate with web servers. The http object performs the client-side activity of the HTTP protocol, connecting to and requesting actions of a web server. To use the object, set the url or any of its component element properties, optionally add cookies or files to be uploaded, and optionally set the user and password if authentication is required. Then issue a getrequest() method to submit the request and obtain a response.
Properties
customheaders$ can be manipulated directly or updated with the addheader() method. The contents is added to the headers sent to the server. If manipulated, it must be constructed with name: value<crlf> sequences, using colon-space breaks between the name and value, and with exactly one CRLF sequence following each header.
|
follow indicates HTTP redirect responses should be followed. It defaults to true (1), but if set to 0, redirect responses will be returned by the getresponse() method.
|
header$ contains the last set of headers from the server.
|
host$ is the hostname, or IP address, of the HTTP server.
|
method$ sets the server communication method. It must be "get" or "post". To simulate a form or file upload, use the post method. To simulate a link click in a browser, use the get method. Generally, if you expect to send a large amount of data, use post.
|
password$ can be specified if the server requires authentication.
|
path$ is the portion of the url after the hostname:port and before the ?query string in. This normally represents a name-mapped file or script on the server.
|
port is the port on which the server is listening. The default ports are 80 for http protocol, and 443 for https protocol, but these values can be configured on the server and may vary.
|
protocol$ should be http or https (for a secure server connection).
|
query$ is the trailing portion of the url which scripts interpret for variable data. The data follows the path and a "?" delimiter, and is often in name=value pairs. The query string must be URL-encoded. The query string can be generated using the addfield() method, or you can manipulate the string directly using the urlencode() function.
|
reason$ contains the last reason text from the server.
|
response$ contains the last response body from the server.
|
status contains the last status code from the server.
|
tcpoptions$ can contain a semicolon- or comma-delimited list of extra options for the socket connection to the http server. The options can include:
• | certificates=ignore|validate|trustreqd (https certificate trust level) |
• | nosslv2, nosslv3, notlsv1, notlsv1.1, notlsv1.2 (disable specific protocols) |
• | tls, tls1.1, tls1.2 (force a specific protocol) |
For example, obj'tcpoptions$="tls1.2;certificates=trustreqd" ensures a high level of TLS security, plus a requirement that the server's certificate is issued by an authority trusted by the local operating system.
|
timeout establishes the timeout for server communication, in seconds. By default, there is no timeout, and the object will wait forever for a server response.
|
url$ is the full address of the currently requested web page. It is represented with a protocol (http/https), a host name, a port, path, and query string, such as "http://example.com/unform.html".
|
userid$ can be specified if the server requires authentication.
|
Methods
addcookie(name$,value$) adds a set-cookie header to the http request headers. Some server applications require receipt of a cookie value.
|
addfield(name$,value$) adds a name=value pair to the query string, with proper url-encoding.
|
addfile(name$,filename$) adds a file to the submission
|
addheader(name$,value$) adds a custom header to the request, useful when interacting with services that look for custom headers. This internally appends "name: value" plus a CRLF to the customheaders$ property.
|
getfields() returns a count of the number of query string fields.
|
getheader$(name$) returns the value of the named header.
|
getname$(n) returns the name of the nth query string value.
|
getresponse([response$][,headers$][,status]) submits the request and fills response$, headers$, and status with the server's response. The response$ value contains the actual content, often an HTML page or XML document. The headers$ field contains linefeed ($0A$) delimited rows of 'name: value' pairs. The status code is the HTTP status of the response, a number whose meaning is defined in the HTTP protocol specification. For example, a status of 200 means OK, and a status of 404 means the requested file wasn't found.
|
getvalue$(n) returns the value of the nth query string value.
|
putfile(file$[,response$][,headers$][,status]) submits the file specified as a PUT request to the server, using the URL path as the server-side file name. Web servers implement strict configuration security for PUT methods, and support for the method is controlled by the web server configuration. A status of 200 or 204 indicates success.
|
setbody(body$[,contenttype$])
Use this to manually set the body submitted to the web server. The body is automatically generated when you add files or fields, but if you want to control the format, for example to submit specific content types (i.e. text/xml), you can use this method.
|
|