Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Mar : Re: TidHTTPServer POST Timeout with PHP client

www.cryer.info
Managed Newsgroup Archive

Re: TidHTTPServer POST Timeout with PHP client

Subject:Re: TidHTTPServer POST Timeout with PHP client
Posted by:"Vern Baker" (javakinet..@gmail.com)
Date:5 Mar 2007 15:09:04

Thank you Remy.  Adding the Content-Length started the engine turning
over.  I was then able to complete the communication between the two
servers.  For others finding this thread, the following PHP script
will work nicely.


<?php
     $fp = fsockopen("127.0.0.1", 5048, $errno, $errstr, 3);

     echo "START Indy Communication<br />
";

     // Catch any errors that may occur...
     // - the one we consistently get is the "Connection Timeout"
error.
     if (!$fp)
     {
        echo "$errstr ($errno)<br />
";
     }
     // If we establish a connection write a simple message.
     else
     {
        $out = "POST XXXXXXX-Put-Stuff-Here-XXXXXXX HTTP/1.1\r
";
        $out .= "Host: 127.0.0.1:5048\r
";
        $out .= "Connection: Close\r
";
        $out .= "Content-Length: 0\r
";
        $out .= "Keep-Alive: 300\r
";
        $out .= "Connection: keep-alive:\r
\r
";

        fwrite($fp, $out);

        /////////////////////////////
    /* OPTION A:  ( Commented out )
        /////////////////////////////
        // Do a keep alive, and read full response
        while ($line = fread($fp, 8192))
        {
           echo $line."
<br>";
           if ($line == false) {
          fclose($fp);
           }
        }
        */


        /////////////////////////////
    // OPTION B: Just read the first two lines, and review response
        /////////////////////////////
    $line = fread($fp, 8192);
        echo $line."
<br>";  // Line 1

    $status_code = array();
    preg_match('/\d\d\d/', $line, $status_code);

    switch( $status_code[0] ) {
    case 200:
       // Success
           echo '[o] Indy Accepted The Request<br>';
           $line = fread($fp, 8192);  // Line 2
           echo $line."
<br>";
       break;
    default:
       echo '[x] Error: HTTP status of: '.$status_code[0].'<br />';
    }
        fclose($fp);

     }

     echo "END Indy Communication<br />
";
?

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive