从search.maven.org获取Maven包最新版本报错,求排查(附PHP代码)
从Maven仓库获取包最新版本时出错
尝试从search.maven.org获取angus-activation-project包的最新版本时触发错误,错误信息如下:
"Error: Failed to retrieve data from the Maven repository"
我编写了以下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; } } ?>
内容的提问来源于stack exchange,提问作者Dam_Jo
相关产品推荐
相关产品推荐

