Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php怎么用telnet提交表单

php怎么用telnet提交表单

发布时间:2018-04-06   编辑:www.jquerycn.cn
本文介绍了php编程中使用telnet提交表单的方法,有关http telnet提交表单的例子,有需要的朋友参考下,希望对大家有所帮助。

在http请求中,提交一个表单,通常有两种方法:
get
post
方法一,提交的表单会显式地添加在url后,以参数形式呈现;
方法二,会在http报文中传送,可以允许很大的长度,而且保密性好。

一,提交第一个表单
这个表单将使用get方法,这主要是由于以下php脚本文件中的全局变量$_get决定的。
file: get.php
 

复制代码 代码示例:
<?php
$string = $_get["text"];
if ($string == "")
    echo "no submission";
else
    echo "you submitted $string";
 
?>
 

功能解析:如果没有提交任何东西,它会返回no submission,否则返回提交的字符串。
telnet test 80 trying 127.0.0.1... connected to test. escape character is '^]'. get /get.php http/1.1 host: test http/1.1 200 ok date: fri, 18 feb 2011 11:46:17 gmt server: apache/2.2.14 (ubuntu) x-powered-by: php/5.3.2-1ubuntu4.7 vary: accept-encoding content-length: 13 content-type: text/html no submission connection closed by foreign host.
现在,加上那个text参数上去:
telnet test 80 trying 127.0.0.1... connected to test. escape character is '^]'. get /get.php?text=hello http/1.1 host:test http/1.1 200 ok date: fri, 18 feb 2011 11:57:17 gmt server: apache/2.2.14 (ubuntu) x-powered-by: php/5.3.2-1ubuntu4.7 vary: accept-encoding content-length: 19 content-type: text/html you submitted hello

二,post方法提交表单
file:post.php
 

复制代码 代码示例:
<?php
$string = $_post["text"];
if ($string == "")
    echo "no submission";
else
    echo "you submitted $string";
 
?>
 

直接提交一些东西,不过报文有所不同:
telnet test 80 trying 127.0.0.1... connected to test. escape character is '^]'. post /post.php http/1.1 host: test referer: test/ content-type: application/x-www-form-urlencoded content-length: 10 connection: close text=hello http/1.1 200 ok date: fri, 18 feb 2011 12:09:01 gmt server: apache/2.2.14 (ubuntu) x-powered-by: php/5.3.2-1ubuntu4.7 vary: accept-encoding content-length: 19 connection: close content-type: text/html you submitted hello
请注意红色部分为要提交的正文,必须与报文头空一行。
它的长度决定content-lenth。它的内容由content-type决定。
此处content-type为application/x-www-form-urlencoded,表示要处理的是一个表单的数据。
第一行post /post.php指出了表单将交给post.php脚本进行处理。
此处也可以是任何cgi脚本,如/cgi-bin/do.pl。

您可能感兴趣的文章:
php怎么用telnet提交表单
php怎么访问接口
Linux开启telnet远程登录服务指南
php接口怎么判断重复提交
js不能提交form表单怎么办
javascript中回车提交表单代码
PHP如何防止post重复提交数据 实例代码
JavaScript 提交表单的实例分享
怎样将HTML表单提交给PHP文件
解决jquery submit()提交表单提示:f[s] is not a function

关键词: telnet  表单提交   
[关闭]