本文整理汇总了PHP中HTTPClient::prepareUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTPClient::prepareUrl方法的具体用法?PHP HTTPClient::prepareUrl怎么用?PHP HTTPClient::prepareUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPClient
的用法示例。
在下文中一共展示了HTTPClient::prepareUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
public function post($url, $data = array(), $params = null)
{
if (!is_array($params)) {
$params = array('resultcb' => $params);
}
if (!isset($params['uri']) || !isset($params['host'])) {
$prepared = HTTPClient::prepareUrl($url);
if (!$prepared) {
if (isset($params['resultcb'])) {
call_user_func($params['resultcb'], false);
}
return;
}
list($params['host'], $params['uri']) = $prepared;
}
if (!isset($params['version'])) {
$params['version'] = '1.1';
}
if (!isset($params['contentType'])) {
$params['contentType'] = 'application/x-www-form-urlencoded';
}
$this->writeln('POST ' . $params['uri'] . ' HTTP/' . $params['version']);
$this->writeln('Host: ' . $params['host']);
if ($this->pool->config->expose->value) {
$this->writeln('User-Agent: phpDaemon/' . Daemon::$version);
}
if (isset($params['cookie']) && sizeof($params['cookie'])) {
$this->writeln('Cookie: ' . http_build_query($this->cookie, '', '; '));
}
$body = '';
foreach ($data as $k => $v) {
if (is_object($v) && $v instanceof HTTPClientUpload) {
$params['contentType'] = 'multipart/form-data';
}
}
$this->writeln('Content-Type: ' . $params['contentType']);
$body = http_build_query($data, '&', PHP_QUERY_RFC3986);
$this->writeln('Content-Length: ' . strlen($body));
$this->writeln('');
$this->write($body);
$this->headers = array();
$this->body = '';
$this->onResponse->push($params['resultcb']);
$this->checkFree();
}