分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

telnet运用http协议+罕见的表单提交方式+聊天

发布时间:2023-09-06 01:17责任编辑:苏小强关键词:http

telnet模拟http请求:

cmd进去以后输入:telnet 127.0.0.1 80 回车(如果程序用不了,那么进去控制面板->程序和功能->打开或关闭windows功能,勾选telnet客户端即可),然后按下ctrl+],回车就可以了

-------------------------

GET请求:

GET http://localhost/test.php HTTP/1.1

HOST:localhost

注意要多一行空格

------------------------

接下来是POST请求:

POST http://localhost/test.php HTTP/1.1

HOST:localhost

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

act=query&name=zzz

--------------------------

file_get_contents模拟表单提交(这里是post提交)

<?php ???????$postData = array( ???????‘title‘=> ‘我是file_get_contents的构造数据‘, ???????‘content‘=> ‘我是file_get_contents的构造数据内容‘, ???????‘publish‘=> ‘发布‘, ???); ???$postData = http_build_query($postData); ???$opts = array( ?????‘http‘=>array( ???????‘method‘=>"POST", ???????‘header‘=>"Host:localhost\r\n" . ?????????????????"Content-type:application/x-www-form-urlencoded\r\n" . ?????????????????"Content-length:" . strlen($postData) . "\r\n", ???????‘content‘=>$postData, ?????) ???); ???$context = stream_context_create($opts); ???file_get_contents("http://localhost/http/index.php",false,$context);

fopen模拟表单提交

<?php ???????$postData = array( ???????‘title‘=> ‘我是fopen的构造数据‘, ???????‘content‘=> ‘我是fopen的构造数据内容‘, ???????‘publish‘=> ‘发布‘, ???); ???$postData = http_build_query($postData); ???$opts = array( ?????‘http‘=>array( ???????‘method‘=>"POST", ???????‘header‘=>"Host:localhost\r\n" . ?????????????????"Content-type:application/x-www-form-urlencoded\r\n" . ?????????????????"Content-length:" . strlen($postData) . "\r\n", ???????‘content‘=>$postData, ?????) ???); ???$context = stream_context_create($opts); ???$fp = fopen("http://localhost/http/index.php","r",false,$context); ???????$fclose($fp);

curl方式模拟表单提交

$url = "http://localhost/http/index.php"; ???$postData = array( ???????‘title‘=> ‘我是curl的构造数据‘, ???????‘content‘=> ‘我是curl的构造数据内容‘, ???????‘publish‘=> ‘发布‘, ???); ???//初始化一个curl会话 ???$ch = curl_init(); ???//设置相应的会话选项 ???curl_setopt($ch, CURLOPT_URL, $url);//设置提交网址 ???curl_setopt($ch, CURLOPT_POST, 1); //设置提交方式,值为1表示肯定 ???curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); //设置提交数据 ???$output = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //提交成功后把数据返回成字符串 ???//执行 ???curl_exec($ch); ???//关闭 ???curl_close($ch); ???echo $output;

编辑未完成,持续更新中...

telnet运用http协议+罕见的表单提交方式+聊天

原文地址:http://www.cnblogs.com/hopelooking/p/7662438.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved