1

By default, GeoServer comes preconfigured with some example workspaces, datastores and layers. One of these workspaces is called it.geosolutions.

If I try to delete this workspace via cUrl and the REST API:

curl -v -u admin:geoserver -XDELETE  http://localhost:8080/geoserver/rest/workspaces/it.geosolutions?recurse=true

, then cUrl returns

HTTP/1.1 404 Not Found

However, if I run the same command on a workspace that does not contain special characters, such as the pre-configured cite workspace:

curl -v -u admin:geoserver -XDELETE  http://localhost:8080/geoserver/rest/workspaces/cite?recurse=true

, then cUrl returns

HTTP/1.1 200 OK

Hence, I guess that the problem in the former case is due to the . in the workspace's name. How can I properly escape such special characters in the URL?

2

While typing the question, I found out how to do it. However, sharing is caring ;-) Maybe this will be useful to somebody else one day.

For escaping URLs when using cUrl to access the GeoServer REST API, special characters can be replaced with their respective ASCII codes, so that the problematic example above becomes:

curl -v -u admin:geoserver -XDELETE  http://localhost:8080/geoserver/rest/workspaces/it%2Egeosolutions?recurse=true

Note that the . has been replaced by %2E.

1

Instead of manually looking up ASCII codes, try URL encoding the string. I don't know much about Curl, but I found a few posts that should help anyone else having this problem. This one deals with Unix/Linux and this one deals with the bash shell.

In most languages, you should be able to find a way to URL encode the string and append it to your URL. This is far easier and more reproducible than manually searching for encoding replacements.

  • Just as a side note, to be safe, you should always URL encode an unknown string when appending it to your URL just in case there are special characters. Also, if you're dealing with other cultures, you should probably make sure you know what encoding the string you're doing to URL encode comes in. – Branco Jul 16 '15 at 16:26
  • 1
    I'm not able to figure it out from the provided links - could anybody please give an example of how this would work for the case described in the question? – Dirk Jul 22 '15 at 11:12

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.