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(); Link to comment https://forums.phpfreaks.com/topic/176669-failed-to-parse-address-error-please-help/ 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 Link to comment https://forums.phpfreaks.com/topic/176669-failed-to-parse-address-error-please-help/#findComment-931439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.