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();

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.