Heim  >  Artikel  >  php教程  >  php 异步请求

php 异步请求

WBOY
WBOYOriginal
2016-06-07 11:45:381237Durchsuche

/**
* 发送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元

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn