[英]ncat command works on command line but not on php script
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脚本中不起作用:
<?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. 而不是返回正确的html,而是返回“您的浏览器发送了服务器无法理解的请求”错误。 How do I fix this?
我该如何解决?
You're writing PHP, therefore the \\n
in your string were parsed by PHP into actual newlines: 您正在编写PHP,因此字符串中的
\\n
被PHP解析为实际的换行符:
$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: 最终发送到
system()
启动的外壳的内容如下:
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. 我必须从echo命令中删除-e。 I checked the packets on Wireshark and what was being sent was this:
我检查了Wireshark上的数据包,发送的内容是这样的:
-e GET / HTTP/1.0
Go figure... 去搞清楚...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.