如何POST到XML API?

时间:2014-02-12 10:39:00

标签: php api

我们正在整合travel API of www.transhotel-dev.com

代码是这样的:

<?php
$servletHOST = "www.transhotel-dev.com";
$servletPATH = "/interfaces/SController";
$pXML = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><Login><Username>Username</Username><Password>Password</Password></Login>";
$pCall = "Login";
$postdata = "pXML=" . urlencode($pXML) . "&pCall=" . urlencode($pCall);

$fp = pfsockopen($servletHOST, 1184);

if ($fp) {
    fputs($fp, "POST $servletPATH HTTP/1.0\n");
    fputs($fp, "Accept: */*\n");

    $strlength = strlen( $postdata );

    fputs($fp, "Content-length: " . $strlength . "\n\n");
    fputs($fp, $postdata . "\n" );

    $output = "";
    while (!feof($fp)) {
        $output .= fgets($fp, 1024);
    }

    fclose($fp);
    echo $output;
}
?>

HTTP压缩和POST方法需要超越这一点。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

以下呼叫需要使用https安全协议 (https://www.transhotel-dev.com:1449/interfaces/SController):

  • 登录
  • AddAmountCardHPlus
  • GetNifInvoices
  • NifAgencyReservations
  • NifHotelReservations
  • ConfirmReservation(包含信用卡数据时)
  • BuildSearchForm
  • LoginRQ
  • LoginB2B
  • CreateAgency
  • NifActivitiesReservations
  • GetActivitiesProvider
  • NifTransfersReservations
  • GetTransfersProvider
  • LoginHPlus
  • UserLogInHPlus

所以你应该使用ssl协议进行登录操作:

$fp = pfsockopen("ssl://www.transhotel-dev.com", 1449);