I have this command:
echo -e 'GET / HTTP/1.0\n\n' | ncat www.website.com 80
Which works perfectly fine in the command line. It doesn't, however, work in the php script:
<?php
$html = system("echo -e 'GET / HTTP/1.0\n\n' | ncat www.website.com 80");
print $html;
?>
Instead of returning the correct html, it returns a "Your browser sent a request the server could not understand" error. How do I fix this?
You're writing PHP, therefore the \\n
in your string were parsed by PHP into actual newlines:
$html = system("echo -e 'GET / HTTP/1.0\n\n' | ncat www.website.com 80");
^^^^^
and what you ended up sending to the shell that system()
started up looked like:
echo -e 'GET / HTTP/1.0
'| ncat www.website.com 80
Try
$html = system("echo -e 'GET / HTTP/1.0\\n\\n' | ncat www.website.com 80");
^--^---note these
instead.
It should look like this:
<?php
$html = system("echo 'GET / HTTP/1.0\n\n' | ncat www.website.com 80");
print $html;
?>
I had to remove the -e from the echo command. I checked the packets on Wireshark and what was being sent was this:
-e GET / HTTP/1.0
Go figure...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.