fsock open error

Discussion in 'PHP' started by jeanmichel, May 19, 2010.

  1. #1
    Ive developed an XML online travel agent system which gets and books reservations with another company, via sending XML messages via HTTP v1.0 POST transactions.

    I have developed the system and it works perfectly fine with thier test servers which the post address is;

    http://otatest.cartrawler.com:20002/cartrawlerota
    Code (markup):
    Now that it's time to move the system to the production server, somethings gone a miss with the script which sends the message-the production box address is;

    https://ota.cartrawler.com/cartrawlerota/
    Code (markup):
    And when i try to post to this address i get the error message;

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

    I think it's something to do with the https transport which is causing an issue, but cant figure it out.

    Here's my script which does the whole thing pretty much;

    function postXMLToURLlive ($server, $path, $xmlDocument) {
    $xmlSource = $xmlDocument;
    $contentLength = strlen($xmlSource);
    $fp = fsockopen('ota.cartrawler.com:443');
    fputs($fp, "POST $path HTTP/1.0\r\n");
    fputs($fp, "Host: $server\r\n");
    fputs($fp, "Content-Type: text/xml\r\n");
    fputs($fp, "Content-Length: $contentLength\r\n");
    fputs($fp, "Connection: close\r\n");
    fputs($fp, "\r\n"); // all headers sent
    fputs($fp, $xmlSource);
    $result = '';
    while (!feof($fp)) {
    $result .= fgets($fp, 128);
    }
    return $result;
    }
    
    
    function getBody($httpResponse) {
    $lines = preg_split('/(\r\n|\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 (markup):
    Anyone with any ideas per say?

    Jean.
     
    jeanmichel, May 19, 2010 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Do you still need to connect to the port 20002 for the production server? Can you ping the connection server from the web server? It looks like it's not even resolving correctly.
     
    jestep, May 20, 2010 IP
  3. jeanmichel

    jeanmichel Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i don't have to connect using port 20002 for the production server.
     
    jeanmichel, May 20, 2010 IP
  4. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    Do you have everything setup in "cartrawlerota/" directory under ota.cartrawler.com subdomain?
    Looks like it cannot resolve ota.cartrawler.com
     
    ivan.kristianto, May 20, 2010 IP
  5. jeanmichel

    jeanmichel Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Im posting an XML formatted message to this location:

    https://ota.cartrawler.com/cartrawlerota
    Code (markup):
    The domain my scripts are housed in are on another webserver and domain totally separate to this cartrawler subdomain.

    Im in agreement that it cannot resolve ota.cartrawler.com, but my question is why, upon pasting the full url into a browser address bar, it is functioning.
     
    jeanmichel, May 20, 2010 IP
  6. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #6
    Hmm. Possibly their firewall blocking the server. Assuming the server is on a different IP than you, you try to use wget or file_get_contents and see if the domain resolves. This will at least tell you if the server is blocking your server out, or if there is another problem.
     
    jestep, May 20, 2010 IP
  7. jeanmichel

    jeanmichel Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Just tried;

    <?php
    $homepage = file_get_contents('https://ota.cartrawler.com/cartrawlerota');
    echo $homepage;
    ?>
    Code (markup):
    And it works fine!!-im about to put this laptop screen through with a PHP for dummies book.
     
    jeanmichel, May 21, 2010 IP
  8. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #8
    i did try your script, but the results are blank.
    But no errors at all.
    And when i tried to open your address on browser it produce errors like this:
    <OTA_ErrorRS Version="1.003" Status="Unknown" ErrorCode="Malformed" ErrorMessage="Premature end of file. Nested exception: Premature end of file."/>
    But i'm not sure where the script went wrong.
     
    ivan.kristianto, May 21, 2010 IP