“错误:无法从 Maven 存储库检索数据”
同时从 search.maven.org 检索最新版本号。 编写了以下 php 代码,我将针对所有其他包进行修改。
<?php
$url = "https://search.maven.org/solrsearch/select?q=a:angus-activation-project&rows=1&wt=json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
if ($response === false) {
echo "Error: Retrieving data from the Maven repository failed";
} else {
$data = json_decode($response);
if ($data === null || !property_exists($data, 'response') || count($data->response->docs) == 0) {
echo "Error: Failed to retrieve the latest version of the artifact from the Maven repository";
} else {
$latestVersion = $data->response->docs[0]->v;
echo "Latest version is" . $latestVersion;
}
}
?> Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
添加此:
如果您使用带有默认用户代理的curl,maven会返回403禁止。这样你的请求看起来像 Firefox