PHP http(file_get_content) GET与POST请求方式
2016-04-22 15:01
423 查看
转自:http://blog.csdn.net/chaoping315/article/details/19013237
1.GET方式请求
[php] view
plaincopy
<?php
$data = array('sParam1'=>'test1','sParam2'=>101,'isAuto'=>1); //定义参数
$data = @http_build_query($data); //把参数转换成URL数据
$aContext = array('http' => array('method' => 'GET',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data ));
$cxContext = stream_context_create($aContext);
$sUrl = 'http://www.mytest.com/test.php'; //此处必须为完整路径
$d = @file_get_contents($sUrl,false,$cxContext);
print_r($d);
?>
2.POST方式请求
[python] view
plaincopy
<?php
$data = array('sParam1'=>'test1','sParam2'=>101,'isAuto'=>1); //定义参数
$data = @http_build_query($data); //把参数转换成URL数据
$aContext = array('http' => array('method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data ));
$cxContext = stream_context_create($aContext);
$sUrl = 'http://www.mytest.com/test.php'; //此处必须为完整路径
$d = @file_get_contents($sUrl,false,$cxContext);
print_r($d);
?>
1.GET方式请求
[php] view
plaincopy
<?php
$data = array('sParam1'=>'test1','sParam2'=>101,'isAuto'=>1); //定义参数
$data = @http_build_query($data); //把参数转换成URL数据
$aContext = array('http' => array('method' => 'GET',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data ));
$cxContext = stream_context_create($aContext);
$sUrl = 'http://www.mytest.com/test.php'; //此处必须为完整路径
$d = @file_get_contents($sUrl,false,$cxContext);
print_r($d);
?>
2.POST方式请求
[python] view
plaincopy
<?php
$data = array('sParam1'=>'test1','sParam2'=>101,'isAuto'=>1); //定义参数
$data = @http_build_query($data); //把参数转换成URL数据
$aContext = array('http' => array('method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data ));
$cxContext = stream_context_create($aContext);
$sUrl = 'http://www.mytest.com/test.php'; //此处必须为完整路径
$d = @file_get_contents($sUrl,false,$cxContext);
print_r($d);
?>
相关文章推荐
- tomcat https部署
- HttpURLConnection 协议 -包含代理判断
- 转载/VMware Workstation环境下的Linux网络设置/适用于无线网络
- wcfDualHTTPBinding配置的服务器与客户端部署于不同机器的问题
- 虚拟机的网络模式
- 【JAVA】网络概念总结
- 谈谈HTTP协议中的短轮询、长轮询、长连接和短连接
- 2016西电校赛网络赛 Problem I 万神的竞赛
- 20160421HTTP Status 500 - java.lang.LinkageError loader constraint violation when resolving method o
- Android之从TCP/IP、HTTP看Socket通信
- 安卓网络请求框架对比
- java中的逆变、协变、不变概念讲解转载自http://www.cnblogs.com/en-heng/p/5041124.html,感谢编程路上的前辈们!
- 通过网络远程控制ARM系统GPIO应用实例
- 2016西电校赛网络赛 Problem J 万神的数列
- Win2003和Win2008防火墙导致FTP服务器不能访问的解决方法(转载自http://www.jb51.net/article/57008.htm)
- 获取网络域名的IP地址
- ios通过URL获取网络图片的原始大小
- Servlet——使用http响应头Content-Disposition下载文件的示例
- 2016西电校赛网络赛 Problem H 数学题
- http