0

I'm trying to post a new SLD style to geoserver and associate it to an existing layer, but keep getting errors. I'm doing the following:

curl -v -u XXXX:xxxxx -X POST "http://localhost/geoserver/rest/layers/landusemap_t11/styles" -H "content-type: application/vnd.ogc.sld+xml" -H "Content-Type: landusemap/collection/t11/defaultstyle/t11.sld" -d "<?xml version=\"1.0\" encoding=\"UTF-8\"?><StyleInfoPost>\t<name>landusemap_t11</name>\t<filename>t11.sld</filename></StyleInfoPost>"

I'm getting:

Could not determine format. Try setting the Content-type header.

What am I doing wrong?

2

The GeoServer REST documentation is quite clear as to what format to use. So assuming you are using SLD 1.0 you need to POST a application/vnd.ogc.sld+xml document to the /styles endpoint, optionally with a name parameter. So in your case something like:

curl -v -u admin:geoserver -X POST -d @file.sld \
 -H "content-type: application/vnd.ogc.sld+xml" http://localhost:8080/geoserver/rest/styles.sld?name=mystylename

Once you have loaded the style you can add it to a layer by putting its name to the layer.

curl -u admin:geoserver -X PUT http://localhost:8080/geoserver/rest/layers/layer.xml \
  -d '<layer><styles><style><name>mystylename</style></styles></layer>'
  • I ran your first command curl -v -u admin:passw -X POST -d @t2.sld -H "content-type: application/vnd.ogc.sld+xml" http://localhost:8080/geoserver/rest/styles.sld?name=landusemap_t2 and got: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 70; Element type "sld:StyledLayerDescriptorxmlns" must be followed by either attribute specifications, ">" or "/>" – vascobnunes Jul 12 '18 at 14:00
  • is your SLD file correct? you may need to add &raw=true to the url if you have "odd" chars in it – Ian Turton Jul 12 '18 at 14:06
  • I validate it in geoserver style editor and get no errors – vascobnunes Jul 12 '18 at 14:21
  • how did you save it on disk? UTF-8 + BOM will break the parser with REST – Ian Turton Jul 12 '18 at 14:22
  • I'm creating it with a python script. The element it is complaining about goes like this in the file: <?xml version="1.0" encoding="UTF-8"?> <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0.0"> – vascobnunes Jul 12 '18 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.