Page Updated: July 30, 2003
Latest Version: 0.1.375
Debug | Install | File I/O | RDF | Network | Sound | Utils | XUL | Zip
Home | Mailing List | Install | Source Code | Downloads | Bugs | docs | clients

Jslib HTTP module
Rajeev J Sebastian

It is quite simple to use the HTTP module. The main operational component,
or controller, is the HTTP object, which has only one method: doOperation(req),
which takes an object Request as a parameter. This method returns true or false,
depending on whether the request was successful or not (done by checking HTTP response

The two attributes of the HTTP object are status and response, which contain the
status number, and the response body respectively.

A request must be configured, before one can use it with the HTTP controller.
The HTTP controller uses a Request object as the model element. The particular
specialization of Request, allows you to perform different types of requests.

All the Request objects take a baseuri at construction as an argument. After this
the object may be configured depending on the features each object offers. The
following gives the various objects and their features (along with the include
script constant).

Note:  Do not attempt to use a base uri in which parameters are already encoded.

for HTTP include script: jslib_http

1) GetRequest : jslib_http_getrequest
  The basic type of request, in which you can access a web location using
  the HTTP GET method. This object must be constructed with the base url of the
  request. Parameters can also be added to the object using the put(key,value) method.
  These parameters are encoded along with the request url.
      var req = new GetRequest("http://localhost/somelocation.html");
      the request uri looks like : http://localhost/somelocation.html?arg1=123&arg2=me

2) PostRequest : jslib_http_postrequest
  This object is similiar in function and interface to the GetRequest object. The only
  differences are that the HTTP POST method is used, and the parameters added using
  the put(key,value) method is added in url-encoded form in the body of the request.
      var req = new PostRequest("http://localhost/somelocation.html");

3) FilePostRequest : jslib_http_filepostrequest
  This object allows you to send a file to a url, which is passed in the body of
  the HTTP request. The only method of this class attaches a Jslib File object
  to the request. The interface is
  where filename and content-type are strings which are sent along with the
  request headers.
      var jsFile = new File("/foo/bar/uglybutt.jpg");
      var req = new FilePostRequest("http://localhost/acceptsfiles.html");

4) MultipartRequest : jslib_http_multipartrequest
  This object is a very powerful yet simple tool. The MultipartRequest like its
  brothers, must be constructed with a base url as an argument. After this,
  it provides a single method put(part), which accepts any of the four types
  of Parts objects.

  The provided parts objects are:

FilePart jslib_http_filepart
  This Part is used to pass a file through the body of
  the request
    filepart.setFile(, , );

TextPart jslib_http_textpart
  This Part is used to pass a long text through the body
  of the request. content-type can be used to provide an
  interpretation of text like text/plain, text/xml, text/html
    textpart.setPart(, , );

URLParametersPart jslib_http_urlparameterspart
  This Part is used to pass urlencoded parameters through
  the request url of the request
    urlparampart.put(, );

BodyParametersPart jslib_http_bodyparameterspart
  This Part is used to pass urlencoded parameters through
  the body of the request.
    bodyparampart.put(, );
  You can also set a name for the part using


The jslib project can be contacted through the mailing list or the member list.
Copyright © 2000-2020. All rights reserved. Terms of Use & Privacy Policy.