Developer Resources
HttpRequest
Overview
HttpRequest allows the user to communicate with HTTP Servers. Both the normal and the secure HTTPS protocols are supported.
Constructor
- HttpRequest()
Events
- HttpRequest.finished
- Fired when asynchronous web events are finished
Properties
- HttpRequest.methodGet
- An integer representing an Http GET request.
- HttpRequest.methodHead
- An integer representing an Http HEAD request.
- HttpRequest.methodPost
- An integer representing an Http POST request.
- HttpRequest.methodPut
- An integer representing an Http PUT request.
Methods
- HttpRequest.binaryRead()
- Returns a MemoryBuffer object with the requested bytes
- HttpRequest.clearRequestHeaders
- Clears all the header items from the list of header items to send when issuing an HTTP request.
- HttpRequest.getMethod
- Returns the HttpRequest method to use when issuing the request
- HttpRequest.getResponseText()
- Returns the server response as a string object
- HttpRequest.getTotalBytes()
- Returns the number of bytes in the input stream
- HttpRequest.getUrl
- Returns the URL string of the request object
- HttpRequest.isDone
- Returns a value indicating whether the request is done
- HttpRequest.isLoading
- Returns a value indicating whether the request object is busy or not.
- HttpRequest.resetPostParameters
- Clears the post parameters.
- HttpRequest.send
- Issues the HTTP request.
- HttpRequest.setAsync
- Turns asynchronous mode on or off
- HttpRequest.setAutoEncode
- Enables or disables url encoding
- HttpRequest.setBasicAuth
- Sets the login and password for the HTTP request.
- HttpRequest.setMethod
- Sets the HttpRequest method type to use when issuing the request
- HttpRequest.setPostData
- Allows the post data payload to be set directly
- HttpRequest.setPostFile
- Sets a form field to a specified filename.
- HttpRequest.setPostValue
- Sets a form field to a specified value.
- HttpRequest.setProxy
- Sets the proxy information for the HTTP request.
- HttpRequest.setReferrer
- Sets the referrer to use when issuing the HTTP request.
- HttpRequest.setRequestHeader
- Adds a header item to the list of header items to send when issuing an HTTP request.
- HttpRequest.setTimeout
- Sets the timeout to use when issuing the HTTP request.
- HttpRequest.setUrl
- Sets the URL to be requested
- HttpRequest.setUserAgent
- Sets the user agent to use when issuing the HTTP request.
Example
var http; // getting a web page http = new HttpRequest; http.setMethod(HttpRequest.methodGet); http.setUrl("http://my.sample.domain.com"); http.send(); alert(http.getResponseText()); // an example demonstrating basic authentication http = new HttpRequest; http.setMethod(HttpRequest.methodGet); http.setUrl("http://my.sample.domain.com"); http.setBasicAuth("test", "this"); http.send(); alert(http.getResponseText()); // an example post method call http = new HttpRequest; http.setMethod(HttpRequest.methodPost); http.setUrl("http://my.sample.domain.com"); http.setPostValue("form_element1", "123"); http.setPostValue("form_element2", "456"); http.send(); alert(http.getResponseText());
HttpRequest.binaryRead()
- function HttpRequest.getTotalBytes(bytes : Number) : MemoryBuffer
Returns
Returns a MemoryBuffer object with the requested bytes
Description
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.
HttpRequest.clearRequestHeaders
- function HttpRequest.clearRequestHeaders()
Description
Clears all the header items from the list of header items to send when issuing an HTTP request.
HttpRequest.getMethod
- function HttpRequest.getMethod() : Integer
Returns
Returns the Http request method to use when issuing the Http request. One of HttpRequest.methodGet, HttpRequest.methodPost, HttpRequest.methodHead, or HttpRequest.methodPut.
Description
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.
HttpRequest.getResponseText()
- function HttpRequest.getResponseText() : String
Returns
Returns the server response as a string object.
Description
Returns a string object with the response text from the web request.
HttpRequest.getTotalBytes()
- function HttpRequest.getTotalBytes() : Number
Returns
Returns the number of bytes remaining in the input stream.
Description
Returns the number of remaining bytes in the input stream. This value represents the total number of bytes available to binaryRead() method invocation.
HttpRequest.getUrl
- function HttpRequest.getUrl() : String
Returns
The url which is being retrieved or which was retrieved.
Description
Returns the URL which is being retrieved or which was retrieved.
HttpRequest.isDone
- function HttpRequest.isDone() : Boolean
Returns
True if the request is finished, false if it is still running.
Description
Returns a boolean value indicating whether the last http request is finished. This value is equivalent to !isLoading().
HttpRequest.isLoading
- function HttpRequest.isLoading() : Boolean
Returns
True if the object is busy, false otherwise.
Description
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.
HttpRequest.resetPostParameters
- function HttpRequest.resetPostParameters()
Description
Clears the post parameters.
HttpRequest.send
- function HttpRequest.send()
Description
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.
HttpRequest.setAsync
- function HttpRequest.setAsync(value : Boolean)
Arguments
- value
- Specifying true turns on asynchronous mode and false turns it off
Description
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.
HttpRequest.setAutoEncode
- function HttpRequest.setAutoEncode(value : Boolean)
Arguments
- value
- True if url encoding it is to be enabled, false otherwise
Description
Sets whether the HttpRequest object should automatically encode GET and POST parameters with url encoding.
HttpRequest.setBasicAuth
- function HttpRequest.setBasicAuth(login : String, password : String)
Arguments
- login
- The login to use for the HTTP Request.
- password
- The password to use for the HTTP Request.
Description
Sets the login and password for the HTTP request.
HttpRequest.setMethod
- function HttpRequest.setMethod(type : String) : Boolean
- function HttpRequest.setMethod(type : Integer) : Boolean
Arguments
- type
- The request type to which to set the request object.
Returns
Returns true if the request type is set, and false otherwise.
Description
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.
HttpRequest.setPostData
- function HttpRequest.setPostFile(post_string : String) : Boolean
Arguments
- post_string
- POST method data payload
Returns
Returns true upon success, false otherwise
Description
Calling setPostData() allows the post data payload to be set directly, in contrast with setPostValue(), which automatically constructs the standard key=value format.
HttpRequest.setPostFile
- function HttpRequest.setPostFile(field : String, filename : String) : Boolean
Arguments
- field
- The form field to set.
- filename
- The filename to which to set the form field.
Returns
Returns true if the form field was set to the specified filename, and false otherwise.
Description
Sets a form field to a specified filename.
HttpRequest.setPostValue
- function HttpRequest.setPostValue(field : String, value : String) : Boolean
Arguments
- field
- The form field for which to set the value.
- value
- The value to which to set the form field.
Returns
Returns true if the form field was set to the specified value, and false otherwise.
Description
Sets a form field to a specified value, which will be used when issuing an HTTP POST request.
HttpRequest.setProxy
- function HttpRequest.setProxy(location : String, port : Integer, login : String, password : String)
Arguments
- location
- The location of the proxy server.
- port
- The port on which to connect to the proxy.
- login
- The login to use when connecting to the proxy.
- password
- The password to use when connecting to the proxy.
Description
Sets the proxy location and, optionally, the proxy port, login, and password.
HttpRequest.setReferrer
- function HttpRequest.setReferrer(referrer : String)
Arguments
- referrer
- The referrer to use when issuing the HTTP request.
Description
Sets the referrer to use when issuing the HTTP request.
HttpRequest.setRequestHeader
- function HttpRequest.setRequestHeader(header : String)
Arguments
- header
- The header to add to the list of headers sent in the HTTP request.
Description
Adds a header item to the list of header items to send when issuing an HTTP request.
HttpRequest.setTimeout
- function HttpRequest.setTimeout(time : Integer)
Arguments
- time
- The timeout time.
Description
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.
HttpRequest.setUrl
- function HttpRequest.setUrl(url : String)
Arguments
- url
- The url to which to send the request.
Description
Sets the URL on the request object.
HttpRequest.setUserAgent
- function HttpRequest.setUserAgent(agent : String)
Arguments
- agent
- The agent to use when issuing the HTTP request.
Description
Sets the user agent to use when issuing the HTTP request.