Connection Guide

Registering to use the service

To obtain an login and password, please register here 

Connecting to the service
Xml requests are submitted to api.travelfusion.com/Xml as the body of an HTTP POST request. You may connect using http or https (secure). Please see the general guidelines for information about our secondary system and correct handling of IPs, URLs and DNS.

In general, UTF-8 encoding should be used. The 'Content-Type' and 'Host' header must be submitted in the HTTP headers. GZip compression must be requested in all HTTP requests. (But please note that Travelfusion's servers may not always return gzip compressed results)

Example java and PHP code is supplied below which can be used to submit the login request to the Travelfusion service and obtain a response. You should insert your login and password into the appropriate place (highlighted in red) before executing this code. This code is supplied as guidance only and it is not necessarily functional or correct and is not recommended for use in any application. It is recommended that you consider connection problems very carefully. There are many reasons that a connection to our system may timeout or fail completely. You should detect these cases and implement retries wherever applicable/ safe to do so. 

Java Code Example

Java Code Example

import java.io.*;
import java.net.Socket;

public class TravelFusionXmlClient {

  public static void main(String[] args) throws Exception {
    String input="<CommandList><Login><Username>*</Username><Password>*</Password></Login></CommandList>";
    String output = sendXml(input);
    System.out.println("RESPONSE: "+output);
  }

  public static String sendXml(String requestString) throws Exception {
    String theHost = "api.travelfusion.com";
    byte[] requestBytes = requestString.getBytes("UTF-8");
    Socket httpSocket = new Socket(theHost, 80);
    try {
      BufferedOutputStream httpOutput = new BufferedOutputStream(httpSocket.getOutputStream());
      httpOutput.write("POST /Xml HTTP/1.0\r\n".getBytes());
      httpOutput.write("Content-Type: text/xml\r\n".getBytes());
      httpOutput.write(("Host: " + theHost + "\r\n").getBytes());
      httpOutput.write("Accept-Encoding: gzip" + "\r\n");
      httpOutput.write(("Content-Length: " + requestBytes.length + "\r\n").getBytes());
      httpOutput.write("\r\n".getBytes());
      httpOutput.write(requestBytes);
      httpOutput.flush();

      BufferedInputStream httpInput = new BufferedInputStream(httpSocket.getInputStream());
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      int count = 0;
      while (true) {
        int b = httpInput.read();
        if (b == -1) {
          break;
        }
        output.write(b);
      }
      byte[] response = output.toByteArray();
      return new String(response, "UTF-8");
    }
    finally {
      httpSocket.close();
    }
  }
}


PHP Code Example

PHP Code Example

<?php
        $config['host'] = "api.travelfusion.com";
        $config['port'] = 80;
        $config['readTimeout'] = 4;
        $config['connTimeout'] = 5;
        $config['compress'] = true;
 
        $request = "
        <CommandList>
            <Login>
                <Username></Username>
                <Password></Password>
            </Login>
        </CommandList>";
 
        // Generate the form header..
        $head = "POST / HTTP/1.0\r\n";
        $head .= "Host: {$config['host']}\r\n";
        $head .= "Content-type: text/xml\r\n";
        $head .= "User-Agent: Mozilla 4.0\r\n";
        if ($config['compress']) {
            $head .= "Accept-Encoding: gzip\r\n";
        }
        $head .= "Content-length: " . strlen($request) . "\r\n";
        $head .= "Connection: close\r\n\r\n";
        $head .= $request;
 
        // Ensure a 5 second socket timeout to prevent lockups
        $h = @ fsockopen($config['host'], $config['port'], $errorno, $errorstr, $config['readTimeout']);
        if (!$h) {
            echo "Unable to connect, $errorstr ($errorno)";
            die();
        }
 
        // Write the headers (previously constructed)
        fwrite($h, $head);
 
        // Set the streams read timeout..
        stream_set_timeout($h, $config['readTimeout']);
 
        // Get info about the stream..
        $info = stream_get_meta_data($h);
 
        // Start Reading
        $headersDone = false;
        while (!feof($h) && !$info['timed_out']) {
            if ($headersDone) {
                $data .= fgets($h, 32768);
            } else {
                $tmp = fgets($h, 1024);
                if ($tmp == "") {
                    continue;
                }
                $tmp = trim($tmp);
                if (($tmp !== false) && ($tmp == "")) {
                    // We can throw away the headers, we don't mind.
                    $headersDone = true;
                }
            }
            $info = stream_get_meta_data($h);
        }
        fclose($h);
 
        if ($info['timed_out']) {
            // Got here because we timed out.
            echo "Read timeout.";
            die();
        }
 
        if ($config['compress']) {
            // Strip out headers (First 10 chars, last 8 chars) and deflate.
            echo gzinflate(substr($data, 10, -8));
        } else {
            echo $data;
        }
?>