php模拟post请求的方法总结

 
更多

php 模拟 post 请求的方法总结。主要有两种办法,通过 fsocket 和通过 curl,下面就简单的举两个案例说明一下 php 如何使用这两种方法模拟 post 请求。

(1)php 通过 fsocket 模拟 post 提交请求

";
	}
}

使用方法如下(注意$url这个参数必须是域名,不可以是localhost这种形式的url):

$purl="http://www.phpernote.com/post.php";
echo "以下是POST方式的响应内容:
"; 
sock_post($purl,"name=php程序员教程网&url=http://www.phpernote.com/");

(2)php 通过 curl 模拟 post 提交请求

'justcoding',
	'fname'=>'phplover',
	'title'=>'myapi',
	'email'=>'123456789@qq.com',
	'phone'=>'13611975347'
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
ob_start();
curl_exec($ch);
$result=ob_get_contents();
ob_end_clean();
echo $result;
curl_close($ch);
打赏

本文固定链接: https://www.cxy163.net/archives/3503 | 绝缘体

该日志由 绝缘体.. 于 2017年04月30日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: php模拟post请求的方法总结 | 绝缘体
关键字: , , , ,

php模拟post请求的方法总结:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter