Home >php教程 >php手册 >php 异步请求

php 异步请求

WBOY
WBOYOriginal
2016-06-07 11:45:381315browse

/**
* 发送HTTP请求并获得响应
* @param url 请求的url地址
* @param param 发送的http参数
*/
function makeRequest($url, $param, $httpMethod = 'GET') {<br>         $oCurl = curl_init();<br>         if (stripos($url, "https://") !== FALSE) {<br>                 curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);<br>                 curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);<br>         }<br> <br>         if ($httpMethod == 'GET') {<br>                 curl_setopt($oCurl, CURLOPT_URL, $url . "?" . http_build_query($param));<br>                 curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);<br>         } else {<br>                 curl_setopt($oCurl, CURLOPT_URL, $url);<br>                 curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);<br>                 curl_setopt($oCurl, CURLOPT_POST, 1);<br>                 curl_setopt($oCurl, CURLOPT_POSTFIELDS, http_build_query($param));<br>         }<br> <br>         $sContent = curl_exec($oCurl);<br>         $aStatus = curl_getinfo($oCurl);<br>         curl_close($oCurl);<br>         if (intval($aStatus["http_code"]) == 200) {<br>                 return $sContent;<br>         } else {<br>                 return FALSE;<br>         }<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

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