php开发文档 会员收费1期 |
本文标签:开发文档 介绍 复制代码 代码如下: <?php function httpRequest($url, $hostName, array $params){ $postParams = array(); foreach ($params as $key=>$val) { $post_params[] = $key.=.rawurlencode($val); } $postString = implode(&, $post_params); $result = ; if (function_exists(curl_init)) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array(Host: . $hostName)); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, DEMO.COM PREMIUM PHP5 Client ver: . phpversion()); curl_setopt($ch, CURLOPT_TIMEOUT, 2); $result = curl_exec($ch); curl_close($ch); } else { $context = array(http => array(method => POST, header => Content-type: application/x-www-form-urlencoded . "\r\n". Host: .$hostName . "\r\n". User-Agent: TEST.COM BC Test PHP5 Client ver: . phpversion() . "\r\n". Content-length: . strlen($postString), content => $postString)); $contextId = stream_context_create($context); $handle = fopen($url, r, false, $contextId); if ($handle) { while (!feof($handle)) $result .= fgets($sock, 4096); fclose($handle); } } return $result; } 测试数据 1、点播信息节目ID:1e390718b72311df97c0.html 2、vip用户ID:123350942 3、普通用户ID:106738702 有权观看的节目ID:cbfb035e962411de83b1.html |