HTTP中的表单请求的三种方式
来源:互联网 发布:安卓便签软件 编辑:程序博客网 时间:2024/06/14 17:35
1.file_get_contents/fopen方式
<?php
$postData = array(
//构造的数据
);
$postData = http_build_query($postData);//处理引号相连
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Host:localhost\r\n".
"Content-type:application/x-www-form-urlencodeed\r\n".
"Content-length:".strlen($postData)."\r\n",
'content' => $postData,
$context = stream_context_create( $opts );
1 . file_get_contents(http://xxxx/xxxx/xxxx.php,false,$context);
2. $fp = fopen("http://xxx","r",false,$context);
$fclose = fclose($fp);
2.CURL方式(需要开启扩展)
//1.开启会话 返回资源句柄
//1.开启会话 返回资源句柄
$ch = curl_init();
//2.会话传输选项设置
curl_setopt($ch,CURLOPT_URL,$url) //设置提交的网址
curl_setopt($ch,CURLOPT_POST,1)//设置数据提交方式
curl_setopt($ch,CURLOPT_POSTFIELDS,$postData)//设置提交的数据
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1)//提交之后,把数据返回为字符串
//3.执行会话
$output = curl_exec($ch);
//4.关闭会话
curl_close($ch);
3.SOCKET方式
<?php
$postData =array();
$postData = http_build_query($postData);
$fp = fsocketopen("localhost",80,$errno,$errorStr,5);
$request = "POST http://xxx HTTP/1.1\r\n";
$request .= "Host:localhost\r\n";
$request .= "Content-type:application/x-www-form-urlencode\r\n";
$request .="Content-length:".strlen($postData)."\r\n\r\n";
$request .=$postData;
fwrite($fp,$request);
//想把请求数据读出来
while(!feof($fp)){
echo fget($fp,1024);
}
fclose($fp);
阅读全文
0 0
- HTTP中的表单请求的三种方式
- Http Post请求的三种常见方式form表单 io流等
- angular的http三种请求方式
- restEasy接受http请求的三种方式
- HTTP返回请求数据的三种方式
- Python中的urllib,urllib三种不同的请求方式
- post 表单中常见的四种表单请求方式
- Http的请求方式
- http的请求方式
- socket,curl,file_get_content三种HTTP模拟表单提交的方式
- 发送HTTP请求的两种方式
- http请求的几种方式
- HTTP协议请求的几种方式
- Android的http两种请求方式
- 【学习】http的8种请求方式
- 关于http的8种请求方式
- http请求的8种方式
- http请求的8种方式
- Cookie进行自动登录
- Java使用Redis实现消息队列
- 1017. A除以B
- mybatis学习之路----动态sql之foreach set
- mysql服务器和客户端时区不同,使用jdbc得到的结果差8小时的问题
- HTTP中的表单请求的三种方式
- 合并分支到Master
- MySQL默认约束
- Codeforces Round #436 (Div. 2) A-D题解
- C语言学习笔记——前言
- 1010 radix
- Codeforces 462C C. Appleman and Toastman【贪心】
- POJ 2109.Power of Cryptography
- Leetcode—3.Longest Substring Without Repeating Characters