本文整理汇总了PHP中HTTP::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::exec方法的具体用法?PHP HTTP::exec怎么用?PHP HTTP::exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP
的用法示例。
在下文中一共展示了HTTP::exec方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIP
/**
* 得到当前用户的公网IP,目前是通过ip138来实现的.
* */
function getIP()
{
$ht = new HTTP("http://www.ip138.com/ip2city.asp", "GET");
#$ht=new HTTP("http://www.dnspod.com/About/IP","GET");
$ret = $ht->exec();
$patt = "/\\[([0-9\\.]*)\\]/";
preg_match_all($patt, $ret, $out);
return array_pop(array_pop($out));
}
示例2: getMatches
/**
* Get Matches and Alliances
*
* Returns an array of matches and the alliances for each match at an event.
*
* @param string $eventKey
* @return array|false
* @throws Exception
*/
public function getMatches($eventKey)
{
if (!is_string($eventKey)) {
throw new Exception("eventKey is not string: " . $eventKey);
}
$request = new HTTP($this->TConfig);
$request->setURL(static::uri . '/event/' . $eventKey . '/matches');
$request->setHeaders($this->setAPIHeaders());
$out = $request->exec();
if ($out['code'] !== 200) {
throw new Exception("Event key matches returned non-200 response code: " . $out['code']);
}
$body = json_decode($out['body'], true);
if (!is_array($body)) {
//throw new Exception("getMatches(...) request body was not array when attempted to be decoded.");
return false;
}
if (count($body) > 0) {
$matches = array();
foreach ($body as $match => $data) {
$matches[$match] = array('matchNumber' => $data['match_number'], 'setNumber' => $data['set_number'], 'red' => $data['alliances']['red']['teams'], 'blue' => $data['alliances']['blue']['teams']);
}
unset($body);
unset($out);
unset($request);
return $matches;
}
return false;
}