Example A-1. A simple script
// A simple example agent.setHost("www.goodtechnology.com"); agent.get("/");
This script, when run, will request the GoodTech homepage. The first line starting with // is a comment. All text on a line after this symbol will be ignored. The second line instructs Flight Simulator that subsequent requests should be made to the server www.goodtechnology.com. The third line actualy tells Flight Simulator to request GoodTech's homepage.
Example A-2. Setting the referring page
// Referrer example agent.setHost('www.goodtechnology.com'); agent.get('/'); agent.setHeader('Referer', 'http://www.goodtechnology.com/'); agent.get('/page2.jsp');
This example extends the first by requesting a second page and telling Flight Simulator to inform the server of the referring page. This information is sent by a web browser to tell the server what page is being linked from. Most of the time you won't need to bother with the referrer; only occasionaly do server-side components examine it.
The agent.setHeader() function allows you to send an arbitrary HTTP header with the next request. If you wanted to specify a header to be sent with every subsequent request, you can use the agent.setPersistantHeader() function.
Example A-3. Setting a persistant header
// Set the user-agent agent.setPersistentHeader('User-Agent', 'Mozilla/4.0'); agent.setHost('www.goodtechnology.com'); agent.get('/'); agent.get('/anotherpage.jsp');
Here, we will send the User-Agent header with both requests to the server. This would be useful for testing systems that recognise the browser making a request and modify their content to suit.