不能通过 telnet 发送 POST 变量?

Posted

技术标签:

【中文标题】不能通过 telnet 发送 POST 变量?【英文标题】:Can't send POST variables through telnet? 【发布时间】:2014-09-01 05:48:38 【问题描述】:

我知道这很简单,但我想不通,如果我用 telnet 发出这样的请求:

machine:~ user$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
POST / HTTP/1.1
Host: localhost
Content-Length: 7

vari=e3
HTTP/1.1 200 OK
Date: Thu, 10 Jul 2014 18:06:33 GMT
Server: Apache/2.2.26 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.6 php/5.5.10 mod_ssl/2.2.26 OpenSSL/0.9.8y DAV/2 mod_perl/2.0.8 Perl/v5.18.2
X-Powered-By: PHP/5.5.10
Content-Length: 7
Content-Type: text/html

VARI = 

没有设置 vari 变量...响应应该有 VARI = e3 因为我有一个输出它的 PHP 行:

echo "VARI = ".$_POST['vari'];
exit;

但是变量没有出现。我错过了什么吗?

【问题讨论】:

【参考方案1】:

尝试添加Content-type 标头:

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

【讨论】:

工作就像一个魅力!谢谢!但是,如果我在标头中省略 Host:,为什么会收到 400 Bad Request? 如果你忽略Host:,它不知道你想要哪个虚拟主机。

以上是关于不能通过 telnet 发送 POST 变量?的主要内容,如果未能解决你的问题,请参考以下文章

JQuery Ajax 请求不通过 post 变量发送

在 telnet 会话中使用变量

curl实现发送Get和Post请求(PHP)

CURL实现发送Get和Post请求(PHP)

如何通过 POST 和 AFNetworking 以变量形式发送数据?

Erlang 和 OTP in Action:为啥不能在 telnet 中调用 get_count?