Connection Guide


Registering to use the service

To obtain an login and password, complete the online registration via our website, remembering to tick the box, in your profile, requesting XML access. You can then use the same login and password to access the XML API.

Connecting to the service

Xml requests are submitted to xml.travelfusion.com/Xml as the body of an HTTP POST request. You may connect using http or https (secure). In general UTF-8 encoding should be used. The 'Content-Type' and 'Host' header must be submitted in the HTTP headers.

Example java and PHP code is supplied below which can be used to submit the login request to the TRAVELfusion service and obtain the 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.

Java Code Example

You can download this code as a java file here.
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 request) throws Exception {
    String theHost = "xml.travelfusion.com";
    byte[] requestBytes = request.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(("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
function test()
{
  $request = "<CommandList><Login><Username>****</Username>"
  			."<Password>****</Password></Login></CommandList>";
  $address = "xml.travelfusion.com";
  $url = 'Xml';
  $service_port = "80";

  $socket = socket_create (AF_INET, SOCK_STREAM, 0);
  if ($socket < 0){
    print "Could not create socket";
    die();
  }
  if (!@socket_connect ($socket, $address, $service_port)) {}
  $length = strlen($request);
  $in = "POST /$url HTTP/1.0\r\nContent-Type: text/xml\r\n"
  			."HOST:$address\r\nContent-Length: $length\r\n\r\n$request";
  $out = '';
  socket_write($socket, $in, strlen ($in));
  while ($out = socket_read ($socket, 32768)) {
    $temp = $temp."$out";
  }
  print $temp;
  die();
}
?> 

About TRAVELfusion | Contact Our API Support Team | Latest API Change - 2nd January