Jump to content

"Failed to parse address error" please help


worldcomingtoanend

Recommended Posts

after I run my long code I get another error on this function below  "failed to parse address" .  Is my snytax okay or is there anything that u can spot in my code that needs changing. Thank you for help.

 

function sendRequest ($request,$host,$port) {
    // +++++++ connection //
    $socket = fsockopen($host, $port, $errno, $errstr);
    if (!$socket) {
        die("<br>$errno - $errstr<br>");
    }
    // +++++++ Request  //
    $httpRequestLine = "post /xml http/1.1\n";
    $httpHeader = "content-length: ";
    $contentLength = strlen($request);
    $httpRequest = $httpRequestLine . $httpHeader . $contentLength . "\n\n" . $request;
    fputs($socket, $httpRequest, strlen($httpRequest));
    // +++++++ read answer //
    $response = "";
    $line = "";
    while (1) {
          $character = fgetc($socket);
          if ($character == "\n") {
              break;
          } else {
              $line .= $character;
          }
    }
    $requestLineElements = explode(" ",$line);
    if (in_array("200",$requestLineElements)) {
        $line = "";
        while (1) {
               $character = fgetc($socket);
               if ($character == "\n") {
                  break;
               } else {
                  $line .= $character;
               }
        }
        $contentHeaderLine = explode(" ",$line);
        $contentLength = $contentHeaderLine[1];
        if ($contentLength > 0) {
            $bytesRead = 0;
            $line = "";
            while (1) {
                  $character = fgetc($socket);
                  if ($character == "\n") {
                      break;
                  } else {
                      $line .= $character;
                  }
            }
            while ($bytesRead < $contentLength) {
                   $c =  fgetc($socket);
                   $response .= $c;
                   $bytesRead = strlen($response);
            }
        }
    } else {
            $response = $line;
    }
    // +++++++ close connection //
    fclose($socket);
    return $response;
}
echo sendRequest();

after I run my long code I get another error on this function below  "failed to parse address" .  Is my snytax okay or is there anything that u can spot in my code that needs changing. Thank you for help.

 

function sendRequest ($request,$host,$port) {
    // +++++++ connection //
    $socket = fsockopen($host, $port, $errno, $errstr);
    if (!$socket) {
        die("<br>$errno - $errstr<br>");
    }
    // +++++++ Request  //
    $httpRequestLine = "post /xml http/1.1\n";
    $httpHeader = "content-length: ";
    $contentLength = strlen($request);
    $httpRequest = $httpRequestLine . $httpHeader . $contentLength . "\n\n" . $request;
    fputs($socket, $httpRequest, strlen($httpRequest));
    // +++++++ read answer //
    $response = "";
    $line = "";
    while (1) {
          $character = fgetc($socket);
          if ($character == "\n") {
              break;
          } else {
              $line .= $character;
          }
    }
    $requestLineElements = explode(" ",$line);
    if (in_array("200",$requestLineElements)) {
        $line = "";
        while (1) {
               $character = fgetc($socket);
               if ($character == "\n") {
                  break;
               } else {
                  $line .= $character;
               }
        }
        $contentHeaderLine = explode(" ",$line);
        $contentLength = $contentHeaderLine[1];
        if ($contentLength > 0) {
            $bytesRead = 0;
            $line = "";
            while (1) {
                  $character = fgetc($socket);
                  if ($character == "\n") {
                      break;
                  } else {
                      $line .= $character;
                  }
            }
            while ($bytesRead < $contentLength) {
                   $c =  fgetc($socket);
                   $response .= $c;
                   $bytesRead = strlen($response);
            }
        }
    } else {
            $response = $line;
    }
    // +++++++ close connection //
    fclose($socket);
    return $response;
}
echo sendRequest();

 

please help

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.