urllib

Provides methods for making HTTP requests. The module is to be replaced by a richer net module, also containing sockets.

module exceptions

  • NoHTTPRequestObject - Exception thrown if no request object could be instanciated.
  • RequestOpenFailed - Exception thrown if an HTTP request could not be opened.
  • SendFailed - Exception thrown if a request could not be sent to the server.

module methods

  • sendRequest(type,url,user,pass,data,headers,callback) - Sends a request to a server.
    To explain the way the optional arguments work I will give examples:
      sendRequest("get", "url")
      sendRequest("post", "url", "data")

      sendRequest("get", "url", [["headername","value"]])
      sendRequest("post", "url", "data", [["headername","value"]])

      sendRequest("get", "url", "user", "pass")
      sendRequest("post", "url", "user", "pass", "data")

      sendRequest("get", "url", "user", "pass", [["headername","value"]])
      sendRequest("post", "url", "user", "pass", "data", [["headername","value"]])

To make the request asynchronous just add a callback function as the last argument to the calls above.

  • type - Type of connection (GET, POST, ...).
  • url - The URL to retrieve.
  • user = null - The username for auth.
  • pass = null - The password. (must be set if user is set!)
  • data = "" - The data to send with the request.
  • headers = [] - Array of headers. Each element in the array should be another array containing [headername,value].
  • callback = null - Callback for asynchronous connections. The callback is called after completion and is passed the request object as 1st Parameter.
  • returns HTTP request object.
  • getURL(url,user,pass,headers,callback) - Shorthand for a GET request. It calls sendRequest with "GET" as first argument. See the sendRequest method for more information.
    • url - The URL to retrieve.
    • user = null - The username for auth.
    • pass = null - The password. (must be set if user is set!)
    • headers = [] - Array of headers. Each element in the array should be another array containing [headername,value].
    • callback = null - Callback for asynchronous connections. The callback is called after completion and is passed the request object as 1st Parameter.
    • returns HTTP request object.
  • postURL(url,user,pass,data,headers, callback) - Shorthand for a POST request. It calls sendRequest with "POST" as first argument. See the sendRequest method for more information.
    • url - The URL to retrieve.
    • user = null - The username for auth.
    • pass = null - The password. (must be set if user is set!)
    • data = "" - The data to send with the request.
    • headers =[] - Array of headers. Each element in the array should be another array containing [headername,value].
    • callback = null - Callback for asynchronous connections. The callback is called after completion and is passed the request object as 1st Parameter.
    • returns HTTP request object.

dependencies

urllib requires a browser with support for HTTPRequest object. Browsers known to work with urllib are Mozilla based browsers, Safari, Konqouror, Opera, IE, Adobe's SVG Viewer plugin, Batik - SVG browser.