HttpRequest allows the user to communicate with HTTP Servers. Both the normal and the secure HTTPS protocols are supported.
// getting a web page; example.com is reserved for documentation and
// serves a single short page, so the whole response fits in an alert
let http = new HttpRequest();
http.setMethod(HttpRequest.methodGet);
http.setUrl("https://example.com");
http.send();
alert(http.getResponseText());
// an example demonstrating basic authentication; httpbin.org is a
// public request-testing service, and /basic-auth/<user>/<password>
// returns 401 until those exact credentials are supplied
http = new HttpRequest();
http.setMethod(HttpRequest.methodGet);
http.setUrl("https://httpbin.org/basic-auth/user/passwd");
http.setBasicAuth("user", "passwd");
http.send();
alert(http.getResponseText());
// an example post method call; /post echoes the form values back
// as JSON, so the response shows what was actually sent
http = new HttpRequest();
http.setMethod(HttpRequest.methodPost);
http.setUrl("https://httpbin.org/post");
http.setPostValue("form_element1", "123");
http.setPostValue("form_element2", "456");
http.send();
alert(http.getResponseText()); Returns a MemoryBuffer object with the requested bytes
Reads a specified number of bytes from the input stream. The bytes are returned in a MemoryBuffer object. If the specified number of bytes is not entirely available, the function returns those bytes which are currently available. If no more bytes are available, an empty MemoryBuffer object is returned.
Clears all the header items from the list of header items to send when issuing an HTTP request.
Returns the Http request method to use when issuing the Http request. One of HttpRequest.methodGet, HttpRequest.methodPost, HttpRequest.methodHead, or HttpRequest.methodPut.
This function returns the Http request method to use when issuing the Http request. One of HttpRequest.methodGet, HttpRequest.methodPost, HttpRequest.methodHead, or HttpRequest.methodPut.
Returns the server response as a string object.
Returns a string object with the response text from the web request.
Returns the number of bytes remaining in the input stream.
Returns the number of remaining bytes in the input stream. This value represents the total number of bytes available to binaryRead() method invocation.
The url which is being retrieved or which was retrieved.
Returns the URL which is being retrieved or which was retrieved.
True if the request is finished, false if it is still running.
Returns a boolean value indicating whether the last http request is finished. This value is equivalent to !isLoading().
True if the object is busy, false otherwise.
Returns a boolean value indicating whether the HttpRequest object is busy. If an asynchronous web request is currently running in the background, a call to this method will return true, indicating that the object is not ready for another request, and that the complete result value is not yet ready for retrieval.
Clears the post parameters.
Issues an HTTP request to the URL location specified on the request object with the specified HTTP method. See the setUrl() and setMethod() calls for more information. The resulting data can be retrieved by subsequently calling getResponseText() and/or binaryRead() methods.
Turns asynchronous mode on or off. If asynchronous mode is on, requests will return immediately and the processing will be done in the background. Upon completion of the request, the finished event is fired.
Sets whether the HttpRequest object should automatically encode GET and POST parameters with url encoding.
Sets the login and password for the HTTP request.
Returns true if the request type is set, and false otherwise.
This function sets the HttpRequest method type to use when issuing the Http request. If the string form of the function is used, the request method type may be either "GET", "POST", "HEAD", or "PUT"; if the integer form of the function is used, the request method type may be either HttpRequest.methodGet, HttpRequest.methodPost, HttpRequest.methodHead, or HttpRequest.methodPut.
Returns true upon success, false otherwise
Calling setPostData() allows the post data payload to be set directly, in contrast with setPostValue(), which automatically constructs the standard key=value format.
Returns true if the form field was set to the specified filename, and false otherwise.
Sets a form field to a specified filename.
Returns true if the form field was set to the specified value, and false otherwise.
Sets a form field to a specified value, which will be used when issuing an HTTP POST request.
Sets the proxy location and, optionally, the proxy port, login, and password.
Returns true upon success, false otherwise
Specifies a file filename to upload with the PUT method
Sets the referrer to use when issuing the HTTP request.
Adds a header item to the list of header items to send when issuing an HTTP request.
Sets the timeout time in seconds to use when issuing the request. The timeout is the maximimum amount of time the request object waits for the server to respond to a request after a connection is established.
Sets the URL on the request object.
Sets the user agent to use when issuing the HTTP request.
Verification is ON by default and should stay on. Turning it off stops |https://| urls being checked at all: the certificate chain is not validated and the host name in the certificate is not compared with the host being contacted. The connection is still encrypted, but an attacker able to redirect it can present their own certificate, read everything sent -- including any credentials passed to setBasicAuth -- and forward the traffic unchanged.
Turn it off only for a host whose certificate cannot be validated and whose traffic you would be willing to send in the clear, typically a test server with a self-signed certificate.