I am trying to post to [url]https://ota.cartrawler.com/cartrawlerota
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;
?>
Does anyone have a solution to this?