An error was encountered while trying to retrieve the latest version of a package from search.maven.org
P粉461599845
P粉461599845 2024-04-05 12:11:23
0
1
1481

"Error: Unable to retrieve data from Maven repository"

Also retrieve the latest version number from search.maven.org. The following php code was written which I will modify for all other packages.

<?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;
    }
    }
?>

P粉461599845
P粉461599845

reply all(1)
P粉409742142

Add this:

curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0");

If you use curl with the default user agent, maven will return 403 Forbidden. This way your request will look like Firefox

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!