0712-2888027 189-8648-0214
微信公众号

孝感风信网络科技有限公司微信公众号

当前位置:主页 > 技术支持 > PHP > Laravel模拟PHP GET/POST请求示例代码

Laravel模拟PHP GET/POST请求示例代码

时间:2024-03-29来源:风信官网 点击: 3408次
Laravel模拟PHP GET/POST请求示例代码
 
模拟GET请求百度天气信息API
 
<?php 
 
//创建连接
$fp = fsockopen('apis.baidu.com',80, $errno, $errstr, 10);
 
if(!$fp) {
echo $errstr;die;
}
 
//
$http = '';
 
//请求行
$http .= "GET /apistore/weatherservice/citylist?cityname=北京 HTTP/1.1\r\n";
 
//请求头
$http .= "Host: apis.baidu.com\r\n";
$http .= "Connection: close\r\n";
$http .= "apikey: 1ae6f08bddd8e5cb8c34e9941cfaa93c\r\n\r\n";
 
//发送
fwrite($fp, $http);
 
//获取结果
$res = '';
 
while(!feof($fp)) {
$res .= fgets($fp);
}
 
echo $res;
 
 
 ?>
 
 模拟POST请求数据信息
 
 <?php 
 
//创建连接
$fp = fsockopen('localhost', 80, $errno, $errstr, 10);
 
//判断
if(!$fp) {
echo $errstr;die;
}
 
$http = '';
 
//请求行
$http .= "POST /class/Public/laravel/http/server.php HTTP/1.1\r\n";
 
//请求头
$http .= "Host: localhost\r\n";
$http .= "Connection: close\r\n";
$http .= "Cookie: username=admin;uid=200\r\n";
$http .= "User-agent: firefox-chrome-safari-ios-android\r\n";
$http .= "Content-type: application/x-www-form-urlencoded\r\n";
$http .= "Content-length: 37\r\n\r\n";
 
//请求体
$http .= "email=123456@qq.com&username=admin\r\n";
 
//发送
fwrite($fp, $http);
 
$res = '';
//获取结果
while(!feof($fp)) {
$res .= fgets($fp);
}
 
echo $res;
 
?>
热门关键词: Laravel 模拟PHP GET POST PHP请求
栏目列表
推荐内容
热点内容
展开