本帖最后由 宝塔用户_sdsifn 于 2024-1-4 16:58 编辑
为了能快速了解并处理您的问题,请提供以下基础信息: 问题描述:通过宝塔API接口创建网站、添加数据库、添加FTP时,返回接口都是404;其他接口(例如删除数据库,修改网站备注等)都可以请求并返回正确的结果 相关截图(日志、错误):(系统语言为PHP) 请求数据输出: array(16) { ["webname"]=> string(17) ""ceshi.haosou.cn"" ["path"]=> string(30) "/data/wwwroot//ceshi.haosou.cn" ["type_id"]=> int(0) ["type"]=> string(3) "PHP" ["version"]=> string(2) "74" ["port"]=> int(80) ["ps"]=> string(15) "ceshi.haosou.cn" ["ftp"]=> string(4) "true" ["ftp_username"]=> string(0) "" ["ftp_password"]=> string(0) "" ["sql"]=> string(4) "true" ["codeing"]=> string(7) "utf8mb4" ["datauser"]=> string(0) "" ["datapassword"]=> string(0) "" ["request_token"]=> string(32) "cd9c991f80b0e701eee0da6888d51a54" ["request_time"]=> int(1704358713)} 返回结果输出: <html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>nginx</center></body></html>
(参考SDK地址:https://www.bt.cn/bbs/forum.php?mod=viewthread&tid=23895)
公共请求方法:
/**
* 请求API
* @param $configName //接口地址 公共配置名称
* @param $p_data //传递参数
* @param $apiUrl //接口地址,此处接口地址需要传递带域名的全地址 默认为空
* @return mixed
*/
public function requestApi($configName, $p_data = array(), $apiUrl = "")
{
if ($apiUrl == "") {
$url = $this->BT_PANEL . $this->config($configName);
} else {
$url = $apiUrl;
}
$GetKeyData = $this->GetKeyData();
$p_data = array_merge($p_data, $GetKeyData);
//登录面板
$headers = array('Authorization:Basic ' . base64_encode($this->BT_USERNAME . ":" . $this->BT_PASSWORD),);
$result = $this->HttpPostCookie($url, $p_data, $headers);
$data = json_decode($result, true);
return $data;
}/**
* 发起POST请求
* @param String $url 目标网填,带http://
* @param Array|String $data 欲提交的数据
* @return string
*/
private function HttpPostCookie($url, $data, $headers = null, $timeout = 60)
{
//定义cookie保存位置
$cookie_file = './' . md5($this->BT_PANEL) . '.cookie';
if (!file_exists($cookie_file)) {
$fp = fopen($cookie_file, 'w+');
fclose($fp);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if ($headers && is_array($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
|
|