Welcome

Login to contribute. Register if you haven't yet.

Support Options

1. Search this site.
2. Make or vote for a Suggestion.
3. Post to Community Support.
3. Contact EditMe Support staff.

Stay Informed

Keep informed of product changes, tutorials and tips via EditMe's Blog and monthly newsletter.

JavaScript API Class: HttpClient

This class implements a stateful HTTP client. Use the util.newHttpClient() method to create new instances of this class. Each instance created this way can be used as a separate HTTP session.

Properties

Name  Type  Access
Description 
autoLogin
boolean read/write
Specifies whether the current user's EditMe session should be used in requests to the current EditMe site. If true, the client will post to the /_Login page to create a session as the current user before any additional requests are made. Reuse an HttpClient instance for multiple calls to avoid having to make this _Login post for each request. This setting has no bearing for requests to sites other than the current EditMe site.
host String read/write The host name to send requests to. For example, www.google.com.
port Number read/write Sets the port to use send requests on. If not set, the port will default to 80 for non-SSL requests and 443 for SSL requests.
responseHeaders Array of response headers read After a request is made, this property will return an array of header objects returned from the server. Each object in the array has a name and value property for reading the header data. For example: httpClient.responseHeaders[0].name + ' = ' + httpClient.responseHeaders[0].value. Returns Null if a request has not been made.
secure boolean read/write Specifies whether requests should be sent over an SSL connection. Defaults to false.
status Number read Returns the status number provided by the server for the last request made. List of HTTP Status Codes
statusText String read Returns the text status provided by the server for the last request made. For example, if status is 404, it might read "File not found". This text is optional in the HTTP specification, so it should not be relied upon.

Functions

Name  Return Type
Description 
basicAuthentication (String1, String2, String3)
None
Instructs the client to provide Basic HTTP Authentication credentials when making requests. String1 is the realm to send - use null if no realm is needed. String2 is the user name. String3 is the password.
get (String) String Performs a GET request. The String argument can either contain the full URL (e.g. http://www.google.com/search?q=editme) or just the URI (e.g. /search?q=editme). In the latter case, the host MUST have been set using the host property before any requests are made. Using a full URL will replace the current host, port and secure properties. The return value is a string containing the response content.
post (String, [Array]) String Just like get() except that a POST method is used instead. Also, the optional Array argument can contain a two-dimmensional array of name/value pairs. For example, httpClient.post('/search', [['q','editme'],['hl','en']]). The return value is a string containing the response content.
setRequestHeader (String1,String2) None Sets a header to be sent with the next request. Headers are reset with each request. The following User-Agent header is sent by default with each request: EditMe API (Jakarta Commons-httpclient/2.0.2

Example

var httpClient = util.newHttpClient();
httpClient.host = 'www.google.com';
var results = httpClient.get('/search?q=editme');