- 浏览: 400805 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
wcjagta:
...
dedecms插件开发教程 -
xc2013:
看起来不错 先下载来试试
ECSHOP完全静态化解决方法 -
greemranqq:
你好,我在xp 上做实验,也是JS css带不过来,关于 ro ...
nginx资源定向 css js路径问题 -
hotsmile:
表结构给出来吧,测试的提示说要注册,
中国移动CMPP短信开发平台通讯包 2.8 -
mengdejun:
gang80306176 写道这个插件怎么用和安装普通插件一样 ...
phpcms2008 sp4单网页编辑器插件
function httpRequestGET($url){ $url2 = parse_url($url); $url2["path"] = ($url2["path"] == "" ? "/" : $url2["path"]); $url2["port"] = ($url2["port"] == "" ? 80 : $url2["port"]); $host_ip = @gethostbyname($url2["host"]); $fsock_timeout=20; if(($fsock = fsockopen($host_ip, 80, $errno, $errstr, $fsock_timeout)) < 0){ return false; } $request = $url2["path"] . ($url2["query"] != "" ? "?" . $url2["query"] : "") . ($url2["fragment"] != "" ? "#" . $url2["fragment"] : ""); $in = "GET " . $request . " HTTP/1.0\r\n"; $in .= "Accept: */*\r\n"; $in .= "User-Agent: Payb-Agent\r\n"; $in .= "Host: " . $url2["host"] . "\r\n"; $in .= "Connection: Close\r\n\r\n"; if(!@fwrite($fsock, $in, strlen($in))){ fclose($fsock); return false; } unset($in); $out = ""; while($buff = @fgets($fsock, 2048)){ $out .= $buff; } fclose($fsock); $pos = strpos($out, "\r\n\r\n"); $head = substr($out, 0, $pos); //http head $status = substr($head, 0, strpos($head, "\r\n")); //http status line $body = substr($out, $pos + 4, strlen($out) - ($pos + 4));//page body if(preg_match("/^HTTP\/\d\.\d\s([\d]+)\s.*$/", $status, $matches)){ if(intval($matches[1]) / 100 == 2){ return $body; }else{ return false; } }else{ return false; } } function httpRequestPOST($url,$post_data){ $url2 = parse_url($url); $url2["path"] = ($url2["path"] == "" ? "/" : $url2["path"]); $url2["port"] = ($url2["port"] == "" ? 80 : $url2["port"]); $host_ip = @gethostbyname($url2["host"]); $fsock_timeout=20;//秒 if(($fsock = fsockopen($host_ip, 80, $errno, $errstr, $fsock_timeout)) < 0){ return false; } $request = $url2["path"] . ($url2["query"] != "" ? "?" . $url2["query"] : "") . ($url2["fragment"] != "" ? "#" . $url2["fragment"] : ""); $needChar = false; foreach($post_data as $key => $val) { $post_data2 .= ($needChar ? "&" : "") . urlencode($key) . "=" . urlencode($val); $needChar = true; } $in = "POST " . $request . " HTTP/1.0\r\n"; $in .= "Accept: */*\r\n"; $in .= "Host: " . $url2["host"] . "\r\n"; $in .= "User-Agent: Lowell-Agent\r\n"; $in .= "Content-type: application/x-www-form-urlencoded\r\n"; $in .= "Content-Length: " . strlen($post_data2) . "\r\n"; $in .= "Connection: Close\r\n\r\n"; $in .= $post_data2 . "\r\n\r\n"; unset($post_data2); if(!@fwrite($fsock, $in, strlen($in))){ fclose($fsock); return false; } unset($in); $out = ""; while($buff = fgets($fsock, 2048)){ $out .= $buff; } fclose($fsock); $pos = strpos($out, "\r\n\r\n"); $head = substr($out, 0, $pos); //http head $status = substr($head, 0, strpos($head, "\r\n")); //http status line $body = substr($out, $pos + 4, strlen($out) - ($pos + 4));//page body if(preg_match("/^HTTP\/\d\.\d\s([\d]+)\s.*$/", $status, $matches)){ if(intval($matches[1]) / 100 == 2){ return $body; }else{ return false; } }else{ return false; } }
$post_data = array("name"=>"xd","sex"=>"man"); httpRequestPOST("http://localhost/post.php",$post_data);
socket写的顺序:
POST /post.php HTTP/1.0
Accept: */*
Host: localhost
User-Agent: Lowell-Agent
Content-type: application/x-www-form-urlencoded
Content-Length: 15
Connection: Close
name=xd&sex=man
普通POST的结果演示:
POST/?username=111&password=222HTTP/1.1
Host:127.0.0.1:8000
User-Agent:Mozilla/5.0(Windows;U;WindowsNT5.2;zh-CN;rv:1.9.0.1)Gecko/2008070208Firefox/3.0.1
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:zh-cn,zh;q=0.5
Accept-Encoding:gzip,deflate
Accept-Charset:gb2312,utf-8;q=0.7,*;q=0.7
Keep-Alive:300
Connection:keep-alive
Referer:http://127.0.0.1:8000/?username=111&password=222
Content-Type:application/x-www-form-urlencoded
Content-Length:25
username=111&password=222
GET的运行结果演示:
GET/?username=111&password=222HTTP/1.1
Host:127.0.0.1:8000
User-Agent:Mozilla/5.0(Windows;U;WindowsNT5.2;zh-CN;rv:1.9.0.1)Gecko/2008070208Firefox/3.0.1
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:zh-cn,zh;q=0.5
Accept-Encoding:gzip,deflate
Accept-Charset:gb2312,utf-8;q=0.7,*;q=0.7
Keep-Alive:300
Connection:keep-alive
Referer:http://127.0.0.1:8000/?username=1&password=2
POST文件上传的结果演示:
POST/?username=111&password=222HTTP/1.1
Host:127.0.0.1:8000
User-Agent:Mozilla/5.0(Windows;U;WindowsNT5.2;zh-CN;rv:1.9.0.1)Gecko/2008070208Firefox/3.0.1
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:zh-cn,zh;q=0.5
Accept-Encoding:gzip,deflate
Accept-Charset:gb2312,utf-8;q=0.7,*;q=0.7
Keep-Alive:300
Connection:keep-alive
Referer:http://127.0.0.1:8000/?username=111&password=222
Content-Type:multipart/form-data;boundary=---------------------------23757983230932
Content-Length:1704
-----------------------------23757983230932
Content-Disposition:form-data;name="phototitle"
12
-----------------------------23757983230932
转自:http://blog.bigqi.com/read.php?157
发表评论
-
php异步操作类库
2011-06-05 16:01 1778httpclient for php 的选择常用方案有以 ... -
织梦HTTP IMAGE下载类
2011-06-05 14:57 1853<?php if(!defined('DEDEINC ... -
php汉字转拼音
2011-06-05 14:41 1571<?php /**************** ... -
PHP采集利器:Snoopy 试用心得
2011-06-05 14:34 14020Snoopy是一个php类,用 ... -
php异步调用 提高用户体验
2011-05-30 14:22 1290这是我的一个技术很好的朋友写的,要我发表在我的博客上可让php ... -
PHP 异步调用 后台调用 持续执行 断开连接/浏览器
2011-05-26 10:31 1679标题很怪,因为我也 ... -
php socket GET POST提交方法(HttpClient) 框架
2011-05-25 18:29 5514<?php /* Version 0.9, 6th ... -
mantis
2011-05-25 09:50 1250mantis 缺陷管理平台Mantis,也做Mantis ... -
Curl参数一览
2011-05-06 17:30 1447* 目录 1. 介绍 ... -
PHPRPC
2011-04-24 11:01 1288PHPRPC 是一个轻型的、安全的、跨网际的、跨语言的、跨平台 ... -
PHP身份证验证程序
2011-04-24 10:56 1241<?php // 计算身份证校验码,根据国家标准GB 116 ... -
nginx 502 Bad Gateway 错误问题收集
2011-04-23 09:43 1732502是FastCGI出现问题,所以从FastCGI配置入手。 ... -
深入理解PHP内存管理之谁动了我的内存
2011-04-12 21:57 828首先让我们看一个问题: ... -
socket模拟post表单
2011-04-11 15:40 2771post的本质就是发送给目的程序一个标志为post的协议串如下 ... -
OAUTH协议
2011-04-09 09:59 1064OAUTH协议为用户资源的 ... -
nginx/windows: 让nginx以服务的方式运行
2011-04-09 09:33 1125在windows下安装了nginx, 郁闷是发现它没有以服 ... -
ThinkPHP处理海量数据分表机制详细代码
2011-04-07 18:27 7177应用ThinkPHP内置的分表算法处理百万级用户数据. ... -
php 分库分表hash算法
2011-04-07 18:16 1670//分库分表算法 function calc_hash_d ... -
nginx配置文件实例: php (fastcgi), perl, proxy, rrd, nagios
2011-04-06 20:33 1804nginx.conf worker_processes 5; ... -
Nginx location 指令的使用(中文翻译)
2011-04-06 20:31 1127location syntax: location [=|~ ...
相关推荐
我们用到最多的模拟POST请求几乎都是使用php curl来实现了,没考虑到PHP socket也可以实现,今天看到朋友写了一文章,下面我来给大家分享一下PHP socket模拟POST请求实例。 以前模拟post请求俺都用PHP curl扩展实现...
PHP版SOCKET模拟提交POST消息 模拟邮箱登陆什么的就可以做了。
VC Socket GET_POST发送HTTP请求示例
php的socket发送post请求示例
VC++ HTTP Get Post请求
VC Socket GET_POST发送HTTP请求示例#资源达人分享计划#
博客:【安卓学习之工具学习】网络通信测试工具-socket/post/get 的附件,博客连接为:http://blog.csdn.net/ljb568838953/article/details/52493675 附件里面含: fiddlersetup_v4.6.2.0.32002.exe NetAssist_v4.2....
主要介绍了使用PHP Socket 编程模拟Http post和get请求 ,需要的朋友可以参考下
用PHP SOCKET构造的POST与GET方法
【初级】利用 SOCKET+PHP 实现发送GET/POST请求,学习HTTP协议,论坛灌水
socket http/https 模拟登录 请求页面等
主要介绍了c#使用Socket发送HTTP/HTTPS请求的实现代码,需要的朋友可以参考下
用Socket实现了发送HTTP请求,源码已经打包了 这些是CHttp里面公开的函数 void SetUrl(char*); //设置网页URL char* GetCookie(); //获取网页cookie void SetCookie(std::string strCookie);//添加cookie std::...
挺适合新手看的,这是我刚接触c++时写的,新手也很容易看懂
通过socket发送get请求,从中国天气网获得指定城市的天气。 该例子在ubuntu 14.04和AM3358的嵌入式linux3.14下实际测试可用。 如果需要在嵌入式linux下使用,需要修改Makefile文件的CC和LINK项,指向相应的交叉...
模拟Socket通讯服务端,实现网络通讯社数据的接收,根据接收数据判断处理
主要介绍了C#基于socket模拟http请求的方法,实例分析了socket模拟http请求的实现技巧,需要的朋友可以参考下
今天给大家带来的是如何利用socket发送GET,POST请求。我借用燕十八老师封装好的一个Http类给进行说明。 在日常编程中相信很多人和我一样大部分时间是利用浏览器向服务器提出GET,POST请求,那么可否利用其它...
这个工具就是一个能在线模拟socket通讯工具,并且能检测通讯是否能正常响应和发送信息