I want to change the default style of the layer in Geo server using the REST API.
For this i have this code:
curl -v -u admin:geoserver -XPUT -H "Content-type: text/xml"
-d <layer><defaultStyle><name>polygon</name></defaultStyle></layer>"
http://mindcrewgis.com/geoserver/rest/layers/pymble:pymble_water
when run this command it is working fine form me.
But when i convert this command in PHP then it is not working for me
My PHP code for above curl command is
<?php
$url="http://mindcrewgis.com/geoserver/rest/layers/pymble:pymble_water";
$contentType = 'text/xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
$data="<layer>
<defaultStyle>
<name>polygon</name>
</defaultStyle>
</layer>";
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type: $contentType",
'Content-Length: '.strlen($data))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$rslt = curl_exec($ch);
$info = curl_getinfo($ch);
?>
But this code is not working for me . There is something wrong in execute curl using PHP.
Best Answer
The following is a modified version of what has been working for us. You'll need to supply your own logic for setting the specific style. In our situation, we base the style on the layer name using a series of if/else statements.