The HttpRequest Object represents a browser's request to a web server. This object allows developers to formulate complex requests which can be passed to the HttpUserAgent for execution.
Constructor
[new] HttpRequest([method, url, data, headers]) |
Creates and returns a new HttpRequest object.
|
|
Arguments
method |
String value. Specifies the request method. GET and POST are possible values. |
url |
String value. Specifies the URL of the request. The string must either start with http:// or /. If the string starts with /, then the server property of the HttpUserAgent must be set. |
data |
A string or object containing the content of the http request. When an object is used to specify the data parameter, then the name:value pairs in the object will automatically be URL encoded. |
headers |
Object or string. If the header is set with an Object, there is one property for each header. If header is set with a string, the string is a series of name:value pairs separated by '\n'. The default headers are as follows:
Accept: */*
Accept-Charset:HttpUserAgent.charset
Host: HttpUserAgent.server
Content-Length: (auto)
Connection: Keep-Alive
User-Agent: HttpUserAgent.agent
Content-Type: application/x-www-formurlencoded
The Content-Type header is included if the method parameter is POST, otherwise Content-Type is not specified.
To post XML, set Content-Type to text/xml. If the data parameter includes <?xml, for example, <?xml version="1.0"?>, then Content-Type will automatically be set to text/xml.
|
|
Instance Properties
The HttpRequest object has four properties: method, url, data, and headers corresponding to the arguments above.
Example
The following example posts data to the AddressBook data table.
//The HttpRequest object is defined...
var req = new HttpRequest("POST", "http://myWebSite.
DataWeb.com/AddressBook/default.view?");
var o = new Object;
o["_redirect"] = "http://myWebSite.
DataWeb.com/AddressBook/default.view?_mode=grid";
o["_table"] = "AddressBook";
o["_queryargs"] = "_mode=insert";
o.FirstName = "John";
o.LastName = "Doe";
o.Email = "JohnDoe@email.com";
req.data = o;
//...then the request is executed
//with the HttpUserAgent object.
var resp = HttpUserAgent.request(req);
response.write(resp);
Related Topics
HttpUserAgent Object, HttpResponse Object