Web Requests

On the server side, you can connect to remote web sites to retrieve content or data. These web features can be used for screen scraping and creating web mashups. The server runs with full privileges, so it's not restricted from interacting with other domains.

Connection Types

Jaxer offers two main API objects for establishing HTTP connections to remote sites:

  • Jaxer.Web performs HTTP requests and directly returns the body of the response.
  • Jaxer.Sandbox performs HTTP requests and then populates the response inside a secure, sandboxed DOM.

Internally each uses the XMLHttpRequest object as the basis for the connection.

Web Connections

Jaxer.Web provides methods for opening connections to get or post data. The remote server, the one to which the connection is made, will see the IP address of the server running your Jaxer application in its log, not the IP address of the client browser using your Jaxer application.

Setting Headers and Other Options

All methods in the Jaxer.Web namespace take as a last, optional parameter a Jaxer.XHR.SendOptions object (except Jaxer.Web.resolve, which doesn't and Jaxer.Web.open, which takes the very similar Jaxer.Sandbox.OpenOptions object). This enables you to, for instance, specify the HTTP headers sent with the request.

Get a Page

Get a Page using a Query

Post to a URL

Customized Web Connections

To have greater control over each connection, Jaxer.XHR.SendOptions can be used as an additional parameter. The send options allow control over:

  • setting the HTTP method of the request
  • setting the content type of the request
  • setting authentication parameters of the request (e.g. username and password)
  • how the response is returned: as text or as xml
  • whether the response is returned as an extended response, Jaxer.XHR.ResponseData

Get a Page (Customized)

This example illustrates one reason you might want to use send options. When logging in to a remote site, a redirect could occur. The testSuccess function allows this.