The HttpUserAgent Object represents the source of incoming requests to the web server. This source is typically a web browser. The methods associated with the HttpUserAgent allow you to emulate web browsers by making server requests from script.
Constructor
[new] HttpUserAgent() |
Creates and returns a new HttpUserAgent object.
|
|
Instance Properties
agent |
User agent string. Defaults to the value in the current browser request. |
charset |
Sets the Accept-Charset header. Defaults to 'ANSI'. 'utf-8' is appropriate for XML operations. |
maxsize |
Maximum size of the response, can be no larger than 5 megabytes.
|
server |
Name of the server receiving requests. This is a string not including 'http://' and not including any subdirectories, e.g., www.DataWeb.com. Setting the server property is not required if a full request path is provided, see the example section below for a demonstration. |
timeout |
Number of seconds to wait for a response from the web server. Default value is 30 seconds. Can be set between 1 and 120 seconds.
|
|
Instance Methods
request |
Sends a request to the web server and returns a HttpResponse object instance. If the server redirects to another URL then the redirect will be followed. |
simpleRequest |
Same as the request() method above, except that redirects will not be followed. |
|
Examples
The following examples return identical HttpResponse objects, 'resp'. The first example demonstrates how to set the server property when making requests. The second example demonstrates that you do not need to set the server property if you provide a full request path to the request() method. The third example demonstrates the properties of the HttpUserAgent object.
Example 1
var ua = new HttpUserAgent();
ua.server = "www.google.com";
var resp = ua.request("/search?q=Socrates");
return resp;
Example 2
var ua = new HttpUserAgent();
var resp = ua.request("http://www.google.com/
search?q=Socrates");
return resp;
Example 3
var ua = new HttpUserAgent();
var resp = ua.request("http://www.google.com/
search?q=Socrates");
response.write("The HttpUserAgent object has the
following properties and values:<br>");
for(var prop in ua)
response.write(prop + " = " + ua[prop] + "<br>");
//
// output:
//The HttpUserAgent object has the
//following properties and values:
//agent = Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
//server = www.google.com
//charset = utf-8
//maxsize = 15360000
//timeout = 30
Related Topics
HttpRequest Object, HttpResponse Object