worldcomingtoanend Posted October 6, 2009 Share Posted October 6, 2009 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(); Quote Link to comment Share on other sites More sharing options...
worldcomingtoanend Posted October 6, 2009 Author Share Posted October 6, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.