/    Sign up×
Community /Pin to ProfileBookmark

fsockopen error

I am trying to post to [url]https://ota.cartrawler.com/cartrawlerota[/url]
and i get the following error:

Warning: fsockopen() [function.fsockopen]: unable to connect to ota.cartrawler.com:-1 (Failed to parse address “ota.cartrawler.com”)

[CODE]<?php
function postXMLToURL ($server, $path, $xmlDocument) {
//$xmlSource = $xmlDocument->dump_mem();
$xmlSource = $xmlDocument;
$contentLength = strlen($xmlSource);
//$fp = fsockopen($server, 80);
$fp = fsockopen($server);
fputs($fp, “POST $path HTTP/1.0rn”);
fputs($fp, “Host: $serverrn”);
fputs($fp, “Content-Type: text/xmlrn”);
fputs($fp, “Content-Length: $contentLengthrn”);
fputs($fp, “Connection: closern”);
fputs($fp, “rn”); // all headers sent
fputs($fp, $xmlSource);
$result = ”;
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
return $result;
}

function getBody ($httpResponse) {
$lines = preg_split(‘/(rn|r|n)/’, $httpResponse);
$responseBody = ”;
$lineCount = count($lines);
for ($i = 0; $i < $lineCount; $i++) {
if ($lines[$i] == ”) {
break;
}
}
for ($j = $i + 1; $j < $lineCount; $j++) {
$responseBody .= $lines[$j] . “n”;
}
return $responseBody;
}

$xmlDocument = simplexml_load_file(‘xml.xml’);

$result = postXMLtoURL(“ota.cartrawler.com”,”/cartrawlerota”,
$xmlDocument);

$responseBody = getBody($result);

$resultDocument = new DOMDocument();
$resultDocument->loadXML($responseBody);

//$resultDocument = domxml_open_mem($responseBody);

header(‘Content-Type: text/xml’);
//echo $resultDocument->dump_mem();
echo $resultDocument;
?>[/CODE]

Does anyone have a solution to this?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJul 18.2009 — Try this:

[code=php]$fp = fsockopen('ota.cartrawler.com:443');[/code]
Copy linkTweet thisAlerts:
@JohnBamptonauthorJul 18.2009 — Thanks, that works. How did you know that it was port 443?
Copy linkTweet thisAlerts:
@MindzaiJul 18.2009 — That's the standard port used for HTTPS.
Copy linkTweet thisAlerts:
@maeraJan 28.2010 — Hello, I have the same problem, try using port 443 option, could you help me? ? I'am new in xml
Copy linkTweet thisAlerts:
@maeraJan 28.2010 — Hi, i have a problem, xml file not read correctly, John could you spend me your function DOMDocument()?

thanks
Copy linkTweet thisAlerts:
@MindzaiJan 28.2010 — DomDocument is not a function, it's a class built in to PHP (assuming you have the module installed and loaded).
Copy linkTweet thisAlerts:
@jean-michelMar 11.2010 — John Bampton,

I do believe you're working on Cartrawlers OTA XML interface for car hire requests in PHP etc.

Could you send me your e-mail address, I am starting this project and you seem a couple of steps ahead of me and could do with a little advice.

Kind Regards,

Jean
Copy linkTweet thisAlerts:
@jean-michelMay 18.2010 — When trying to post to https://ota.cartrawler.com/cartrawlerota/

we get response;

Warning: fsockopen() [function.fsockopen]: unable to connect to ota.cartrawler.com:-1 (Failed to parse address "ota.cartrawler.com") in /home/visionca/public_html/Quote.php on line 63


[CODE]
function postXMLToURLlive ($server, $path, $xmlDocument) {
$xmlSource = $xmlDocument;
$contentLength = strlen($xmlSource);
$fp = fsockopen('ota.cartrawler.com');
fputs($fp, "POST $path HTTP/1.0rn");
fputs($fp, "Host: $serverrn");
fputs($fp, "Content-Type: text/xmlrn");
fputs($fp, "Content-Length: $contentLengthrn");
fputs($fp, "Connection: closern");
fputs($fp, "rn"); // all headers sent
fputs($fp, $xmlSource);
$result = '';
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
return $result;
}


function getBody($httpResponse) {
$lines = preg_split('/(rn|r|n)/', $httpResponse);
$responseBody = '';
$lineCount = count($lines);
for ($i = 0; $i < $lineCount; $i++) {
if ($lines[$i] == '') {
break;
}
}
for ($j = $i + 1; $j < $lineCount; $j++) {
$responseBody .= $lines[$j] . "n";
}
return $responseBody;
}

$xmlDocument = '<?xml version="1.0" encoding="UTF-8"?>
<OTA_VehAvailRateRQ
xmlns="http://www.opentravel.org/OTA/2003/05"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_VehAvailRateRQ.xsd"
Target="Production"
Version="1.005">
<POS>
<Source ISOCurrency="' . $currencyID . '">
<RequestorID Type="16" ID="198094" ID_Context="CARTRAWLER" />
</Source>
</POS>
<VehAvailRQCore Status="Available">
<VehRentalCore PickUpDateTime="' . $pickupYear . '-' . $pickupMonth . '-' . $pickupDate . 'T' . $pickupHour . ':' . $pickupMinute . ':00" ReturnDateTime="' . $returnYear . '-' . $returnMonth . '-' . $returnDate . 'T' . $returnHour . ':' . $returnMinute . ':00">
<PickUpLocation CodeContext="CARTRAWLER" LocationCode="' . $pickupID . '" />
<ReturnLocation CodeContext="CARTRAWLER" LocationCode="' . $returnID . '" />
</VehRentalCore>
<DriverType Age='' . $age . ''/>
</VehAvailRQCore>
<VehAvailRQInfo PassengerQty='' . $carGroupID . ''>
<Customer>
<Primary>
<CitizenCountryName Code='' . $residenceID . '' />
</Primary>
</Customer>
<TPA_Extensions>
<ConsumerIP>' . $remoteIP . '</ConsumerIP>
</TPA_Extensions>
</VehAvailRQInfo>
</OTA_VehAvailRateRQ>';

$result = postXMLtoURLlive("ota.cartrawler.com", "/cartrawlerota", $xmlDocument); //live environment(0)

[/CODE]


Could anybody advise?

Kind Regards
×

Success!

Help @JohnBampton spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...