2011-05-23 141 views
3

我已经做了一个简单的网页在PHP中测试来自telnet的请求。 这里是网页(使用example.php)的代码:http post请求帮助

<html> 
<body> 
<form method="post" action="example.php>"> 
Your Name:<input type="text" size="12" maxlength="12" name="Name"><br /> 
<input type="submit" value="submit" name="submit"> 
</form> 
<?php echo $_POST["Name"]; ?> 
</body> 
</html> 

这个工作从浏览器,但我想从远程登录进行测试。我试过:

telnet localhost 80 
POST example.php HTTP/1.0 
Host: localhost 
Content-Type: text/html; charset=iso-8859-1 
Content-Length: 11 

Name=myname 

但它不工作....任何帮助吗?

+3

既可以看看Fiddler或Wireshark,看看真正的POST数据包包含什么,或者阅读RFC更深一点;) – Konerak 2011-05-23 07:59:49

+0

“但它不工作....”对不起,但这不是好的一种错误信息。 - 告诉我们更多关于系统的反应和行为。检查Web服务器访问/错误日志等。 – 2011-05-23 08:02:25

+0

是的,你是对的...我会尽力挖掘更深的:)无论如何,从服务器的响应是一个HTTP/1.1 400错误的请求 – user601836 2011-05-23 08:07:38

回答

2

改变您的内容类型

POST /example.php HTTP/1.0 
Host: localhost 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 11 

Name=myname 
4

Konerak是对的。看看真实的请求。例如Content-Type。我只是试了一下,得到了

Content-Type: application/x-www-form-urlencoded 

你也错过了第二个表单域:你的按钮。但我想这并不重要......

Name=myname&submit=submit 

看看http://en.wikipedia.org/wiki/POST_%28HTTP%29的一些细节,并为您的研究一个很好的起点......

更新:尽量

POST /example.php HTTP/1.0 
Host: localhost 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 11 

Name=myname 

至少,这个工作对我来说...