Access to GeoServer in the layers list using the REST interface

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

  Recently, in the process, there is a demand for management operation to the GeoServer in the external program, through access to information found that the REST interface GeoServer can meet the demand of. The REST interface uses HTTP calling, no need to login to Web management interface can be invoked and simple configuration on GeoServer.

  GeoServer official website of the configuration of REST API and sample introduction.:

  The following procedure by using REST interface, list the request GeoServer layer.

<?php
    $url = "http://localhost:8180/geoserver/rest/layers/";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//Set to true, said the acquisition of content as a string
    curl_setopt($ch, CURLOPT_VERBOSE, true);//Set to true, the abnormal return during the execution of the
    curl_setopt($ch, CURLOPT_GET, True);
    $passwordStr = "admin:geoserver";//The GeoServer Username: password
    curl_setopt($ch, CURLOPT_USERPWD, $passwordStr);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept:application/json"));//HTTP request header information
    $successCode = 200;
    $buffer = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    if($info['http_code'] != $successCode){
        $msgStr = "The request failed!";
        echo $msgStr;
    }else{
        $outputArray = json_decode($buffer, true);
        $layerInfos = $outputArray['layers']['layer'];
        foreach($layerInfos as $k => $v){
            $layerNames[] = $v['name'];
        }
        echo json_encode($layerNames);
    }
?>


Blog statement:

  All the articles in this blog, in addition to the title “ reprinted ” words, all articles are original works or finish summary in the data access, refers to non reprint articles please specify this statement. — — blog Park -pallee

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Neil at October 23, 2013 - 7:47 PM