Home >php教程 >php手册 >一段简单的curl代码

一段简单的curl代码

WBOY
WBOYOriginal
2016-06-06 20:14:54969browse

在移动后端开发中经常遇到需要对接口进行调试,使用curl可以带来很大的便捷,记录下我常用的一段代码方便以后重用 [代码片段]

在移动后端开发中经常遇到需要对接口进行调试,使用curl可以带来很大的便捷,记录下我常用的一段代码方便以后重用

$data = array('userid'=>123,'switch'=>array('msg_accept','msg_voice' ,'msg_vibrated')); $request = http_build_query($data); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,'http://localhost/system/sys.php'); curl_setopt($ch,CURLOPT_POST,TRUE); curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); curl_setopt($ch,CURLOPT_POSTFIELDS,$request); echo __LINE__,'|',date('Y-m-d H:i:s'),PHP_EOL; $result = curl_exec($ch); echo __LINE__,'|',date('Y-m-d H:i:s'),PHP_EOL; var_dump($result); ,
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn