Failing to Get data over HTTP from FlightGear

FlightGear has a neat built-in HTTP server that lets you view and alter properties of the simulation.

The server will spit the entire tree (and some rudimentary controls for changing values) out if you open the root folder, but the wiki implies that getting/setting individual variables over HTTP (without needing to manually navigate to each property and click a button to set a new value) should be possible.

I think that pitching the server the name of the node that contains the property I want will cause the server to return the current value, and somehow sending the node name paired with a value will set the value. I can’t figure out how to do this.

My knowledge of HTTP is pretty weak so I spent a little bit of time noodling through some info. Once I was able to refine some search parameters I gleaned enough to write this script that should at least dump the base web page HTML (and the headers) at me:

var req = new XMLHttpRequest();'GET', 'HTTP://', false, 'localhost');

This doesn’t seem to work once req.send() is run. I get an error in the Javascript console that says Access-Allow-Control-Origin doesn’t allow someone on my domain to make the request. This doesn’t make sense since I’m on the same computer, which is the same domain (localhost)…. right? Like I said, my HTTP/Javascript/etc knowledge is super weak. I’m not even sure if I’m using the terminology right.

I checked the source of the FlightGear HTTP server and sure enough it doesn’t include in the returned header a special allowance to enable cross-domain scripting. I suppose I could submit a feature request. I also suppose I could see if I can compile the source and make the change myself (a trivial two-line add).

It’s more likely that I’m doing this all wrong. Maybe some sleep will help.

This entry was posted in Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s