PHP模拟post,get
来源:互联网 发布:位面淘宝txt全集下载 编辑:程序博客网 时间:2024/05/19 13:22
post调用
$URL = 'http://xx/xx/xx/'; //需要提交到的页面
//下面这段是要提交的数据
$post_data['email'] = $_POST['email'];
$post_data['password'] = $_POST['password'];
echo get_postData($URL,$post_data);
get调用
$URL = 'http://xx/xx/xx/?token='.$token; //需要提交到的页面
echo get_getData($URL);
function get_getData($URL){
$ch = curl_init($URL) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;
$output = curl_exec($ch) ;
curl_close($fch) ;
return $output;
}
function get_postData($URL,$post_data){
$referrer="";
$URL_Info=parse_url($URL);
if($referrer==""){
$referrer=$_SERVER["SCRIPT_URI"];
}
foreach ($post_data as $key=>$value){
$values[]="$key=".urlencode($value);
}
$data_string=implode("&",$values);
if (!isset($URL_Info["port"])) {
$URL_Info["port"]=80;
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referrer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n";
}
$fp = fsockopen($URL_Info["host"], $URL_Info["port"]);
fputs($fp, $request);
$i = 0;
while(!feof($fp)) {
$result = fgets($fp, 1024);
$length = strlen($result);
$s1 = substr($result, 0, 1);
$s2 = substr($result, $length - 3, 1);
if($s1 == '{' && $s2 == '}')
$resultover = $result;
}
fclose($fp);
return $resultover;
}
- PHP模拟post,get
- php使用curl可以get 模拟post
- php 用fsocket模拟浏览器POST GET
- php模拟post和get方法
- php+socket模拟get,post请求
- PHP CURL模拟GET及POST函数
- PHP CURL模拟GET及POST函数
- PHP模拟GET和POST提交数据
- 用socket模拟php中get,post
- PHP实用函数:stream_context_create()模拟POST/GET
- PHP函数:stream_context_create()模拟POST/GET
- PHP:stream_context_create函数模拟POST/GET请求
- [php]模拟socket发送GET,POST请求
- PHP函数stream_context_create()模拟POST/GET
- CURL模拟POST/GET
- stream_context_create()模拟POST/GET
- stream_context_create()模拟POST/GET
- stream_context_create()模拟POST/GET
- ubuntu11.0.4下编译Android2.3源码过程
- ArcCatalog禁用ArcSDE连接配置界面的保存密码勾选项
- 杂感-生活只给你留了一条路,要么前进,要么后退
- 接收控制台的输入并输出
- oracle创建表空间.创建用户.创建表
- PHP模拟post,get
- SAP 屏幕逻辑流
- iphone多线程-学习记录
- [C++][Thread] 转:线程池原理及创建(C++实现)
- STM32F 使用的几个要点
- Android小项目集合
- 我的第一个Oc程序
- Solaris关机命令
- Android API Level