本文整理匯總了PHP中HttpClient::get_body方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpClient::get_body方法的具體用法?PHP HttpClient::get_body怎麽用?PHP HttpClient::get_body使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HttpClient
的用法示例。
在下文中一共展示了HttpClient::get_body方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: checkNodeStatus
/**
* 檢查存儲節點狀態
* @param string $host
* @return int
*/
public function checkNodeStatus($host)
{
$url = $host . '/api.php';
$data = array('route' => "store/status", 'callback_url' => PluginMiniStoreOption::getInstance()->getMiniyunHost() . "info.htm");
$http = new HttpClient();
$http->post($url, $data);
$result = $http->get_body();
$result = @json_decode($result, true);
if ($result["status"] == "1") {
return 1;
}
return -1;
}
示例2: pushFileConvert
/**
* 把文檔進行轉換
* @param array $version
* @param string $mimeType 如mineType為空,則使用version.mime_type
*/
private function pushFileConvert($version, $mimeType)
{
if (empty($mimeType)) {
$mimeType = $version["mime_type"];
}
$miniHost = PluginMiniDocOption::getInstance()->getMiniyunHost();
$siteId = MiniSiteUtils::getSiteID();
$signature = $version["file_signature"];
$node = PluginMiniDocNode::getInstance()->getConvertNode($signature);
if (!empty($node)) {
$url = $node["host"] . '/api.php?route=file/convert';
$downloadUrl = $miniHost . "api.php?route=module/miniDoc/download&signature=" . $signature;
$callbackUrl = $miniHost . "api.php?route=module/miniDoc/report&node_id=" . $node["id"] . "&signature=" . $signature;
$data = array('signature' => $signature, 'site_id' => $siteId, 'mime_type' => $mimeType, 'download_url' => $downloadUrl, "callback_url" => $callbackUrl);
$http = new HttpClient();
$http->post($url, $data);
$result = $http->get_body();
$result = json_decode($result, true);
if ($result['status'] == 1) {
$this->updateDocConvertStatus($node["id"], $version["file_signature"], 1);
}
}
}
示例3: searchKeyWordAndSiteId
/**
* 根據關鍵字+SiteId向迷你搜索發送請求
* @param string $key 關鍵字
* @param string $siteId 站點ID
* @return array 返回signature列表
*/
private function searchKeyWordAndSiteId($siteId, $key)
{
$opts = array("before_match" => "<span style='background-color: #ffff00'><b>", "after_match" => "</b></span>", "chunk_separator" => " ... ", "limit" => 150, "around" => 75);
//向迷你搜索服務器發送搜索請求
$node = PluginMiniSearchNode::getInstance()->getBestNode();
if (!empty($node)) {
$url = $node["host"] . '/api.php';
$data = array('route' => "file/search", 'site_id' => $siteId, 'key' => $key);
foreach ($opts as $key => $value) {
$data[$key] = $value;
}
$http = new HttpClient();
$http->post($url, $data);
$body = $http->get_body();
$body = json_decode($body, true);
if ($body['status'] == 1) {
PluginMiniSearchNode::getInstance()->newSearch($node["id"]);
return $body["result"];
}
}
return array();
}
示例4: pushReplicateTask
/**
* 推送任務到文件冗餘備份服務器
* @param $miniHost
* @param $task
*/
private function pushReplicateTask($miniHost, $task)
{
$node = PluginMiniStoreNode::getInstance()->getNodeById($task->node_id);
//如目標服務器不可用,則不用發送請求
if ($node["status"] == 1) {
$signature = $task->file_signature;
$version = MiniVersion::getInstance()->getBySignature($signature);
$downloadUrl = $miniHost . "api.php?route=module/miniStore/download&signature=" . $signature;
$callbackUrl = $miniHost . "api.php?route=module/miniStore/replicateReport&signature=" . $signature . "&node_id=" . $node["id"];
//向迷你存儲發送冗餘備份請求
$data = array('route' => "file/replicate", 'size' => $version["file_size"], 'signature' => $signature, 'download_url' => $downloadUrl, "callback_url" => $callbackUrl);
$http = new HttpClient();
$http->post($node["host"] . "/api.php", $data);
$content = $http->get_body();
if (!empty($content)) {
$status = @json_decode($content)->{"status"};
if ($status == 1) {
//目標服務器接受請求後,更改任務狀態
$task->status = 1;
$task->save();
}
}
}
}
示例5: buildTask
/**
* 編製索引
* @param $miniHost
* @param $siteId
* @param $task
*/
private function buildTask($miniHost, $siteId, $task)
{
$nodeId = $task->node_id;
$signature = $task->file_signature;
$node = PluginMiniSearchNode::getInstance()->getNodeById($nodeId);
if (!empty($node)) {
$url = $node["host"] . '/api.php?route=file/build';
$downloadUrl = $miniHost . "api.php?route=module/miniSearch/downloadTxt&signature=" . $signature;
$callbackUrl = $miniHost . "api.php?route=module/miniSearch/report&node_id=" . $node["id"] . "&signature=" . $signature;
$data = array('signature' => $signature, 'site_id' => $siteId, 'download_url' => $downloadUrl, "callback_url" => $callbackUrl);
$http = new HttpClient();
$http->post($url, $data);
$result = $http->get_body();
$result = @json_decode($result, true);
if ($result['status'] == 1) {
//修改task狀態
$task->status = 1;
$task->save();
}
}
}
示例6: previewContent
/**
* 在線瀏覽文件獲得內容
* @param string $path 文件當前路徑
* @param string $type 文件類型,可選擇pdf/png
* @throws
* @return NULL
*/
public function previewContent($path, $type)
{
$file = MiniFile::getInstance()->getByPath($path);
// 權限處理
if (empty($file)) {
return array('success' => false, 'msg' => 'file not existed');
}
$fileBiz = new FileBiz();
$canRead = $fileBiz->privilege($path);
if (!$canRead) {
throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409);
}
//獲得文件當前版本對應的version
$version = PluginMiniDocVersion::getInstance()->getVersion($file["version_id"]);
$signature = $version["file_signature"];
$localPath = PluginMiniDocOption::getInstance()->getMiniDocCachePath() . $signature . "/" . $signature . "." . $type;
if (!file_exists($localPath)) {
//文檔還在轉換中
$node = PluginMiniDocNode::getInstance()->getConvertNode($signature);
if (empty($node)) {
throw new MFileopsException(Yii::t('api', 'convert error'), MConst::HTTP_CODE_412);
}
//根據情況判斷是否需要向迷你文檔拉取內容
$parentPath = dirname($localPath);
//如果緩存目錄不存在,則需要創建
if (!file_exists($parentPath)) {
MUtils::MkDirsLocal($parentPath);
}
//文件不存在,則需要從迷你文檔拉取文件內容
$url = PluginMiniDocNode::getInstance()->getDownloadUrl($node["id"], $version, $type);
$http = new HttpClient();
$http->get($url);
$status = $http->get_status();
if ($status == "200") {
$content = $http->get_body();
//把文件內容存儲到本地硬盤
file_put_contents($localPath, $content);
Yii::log($signature . " get " . $type . " success", CLogger::LEVEL_INFO, "doc.convert");
} else {
if (!($version["doc_convert_status"] == -1)) {
//如迷你文檔服務器不存在該文檔,說明迷你文檔服務器發生了變動
//這個時候自動啟動負載均衡機製,把文檔重新轉換
PluginMiniDocVersion::getInstance()->pushConvertSignature($signature, "");
Yii::log($signature . " get " . $type . " error", CLogger::LEVEL_ERROR, "doc.convert");
}
}
}
if (file_exists($localPath)) {
if ($type === "png") {
$contentType = "image/png";
}
if ($type === "pdf") {
$contentType = "Content-type: application/pdf";
}
//Firefox+混合雲模式下直接輸出內容
//其它瀏覽器使用sendfile模式輸出內容
$isSendFile = true;
if (MiniUtil::isMixCloudVersion()) {
$ua = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : NULL;
if (strpos($ua, "Firefox") > 0 || strpos($ua, "Safari") > 0) {
$isSendFile = false;
}
}
if ($isSendFile) {
header('Location: ' . MiniHttp::getMiniHost() . "assets/minidoc/" . $signature . "/" . $signature . "." . $type);
} else {
Header("Content-type: " . $contentType);
echo file_get_contents($localPath);
exit;
}
}
}