Task: Get a response from the server after POST XML request.

We request as follows:

$_SESSION['echo'] = ''; header('Content-Type: text/html; charset=UTF-8'); $sock = fsockopen($host, $port); fputs($sock, $post); echo "<pre>"; while (!feof($sock)) { $echo = htmlspecialchars(fgets($sock)); echo $echo; $_SESSION['echo'] .= $echo; } echo "</pre>"; fclose($sock); 

So far so good, we get the data. But the size of the data is not known (to be completely accurate, it depends on what we send to the server, and it can be as much as 1-2 kb, and can reach mb).

When receiving a long data stream, the lines are broken:

 хидеры 7cb8 строка раз bff8 строка два 5ffd0 строка три 10a7b строка четыре 

and further in the same vein.

The question is:
How to get rid of these hexadecimal values ​​that wedge between the lines?
Is it possible to get a very long line without breaking it up into several lines?

Ps Yes, cUrl would be more convenient, only the server issuing information does not allow. We receive XML in the form of one line, long and terrible. Sometimes, even the response information is lost a little, but there is a suspicion that these are some problems of the Internet.

    1 answer 1

    Why not?

     $sock = fsockopen($host, $port); fputs($sock, $post); $content = ""; while (!feof($sock)) { $content .= fgets($sock); } echo htmlspecialchars($content); fclose($sock); 
    • In general, there is a right decision in your thought, but when changing places of variables, the same error still occurs. When a long string is received (if it is split into several lines), hexadecimal values ​​are added after the line (I have a suspicion that it writes the number of received characters \ byte \ something else). - Dan the Hat