2

I'm using PHP cURL to upload a Shapefile to GeoServer. It works fine in a development server. But when I deploy to Stage server and I try the same I get:

405 Method Not Allowed

The requested method PUT is not allowed for the URL /geoserver/rest/workspaces/my_workspace/datastores/my_datastore/file.shp.

Apache/2.4.18 (Ubuntu) Server at my.stage-domain.com Port 80

I've tried Google about how to enable PUT requests, but nothing seems to work. I've installed both development and stage servers (both running Ubuntu 16.04) and I didn't had to enable PUT on my development server. It just worked.

Looking around here I've found this question and the answers suggests to register the webapp, but I don't even know how to do that...

Do you have any suggestions? I'm really stuck here...

UPDATE:

As suggested in comments, I replaced the Linux binary version for the geoserver.war file running over Tomcat 8. I've also reinstalled the server so now I have Ubuntu 17.04 and Apache 2.4.27 as in my development server. Unfortunately, the issue remains exactly the same. So I guess it's a web server issue.

My access.log file on Apache2 logs shows:

aaa.bbb.ccc.ddd - - [08/Jan/2018:15:02:27 +0000] "PUT /geoserver/rest/workspaces/my_workspace/datastores/my_datastore/file.shp HTTP/1.1" 405 629 "1" "-"

UPDATE 2:

Some answers and comments suggest to use POST instead of PUT method. I am uploading a zipped shapefile to an existing datastore. This:

/workspaces/{workspaceName}/datastores/{storeName}/{method}.{format}

Uploads files to the data store, creating it if necessary

In the API docs it says clearly that I must use PUT

Invalid POST

Use PUT

  • are you using the correct username/password? check the geoserver log file and see if you get to GS, it looks as if this might be an apache error message. – Ian Turton Jan 5 '18 at 10:29
  • Yes, I've updated my config files with the correct user/pass for stage server... I'll try to check GS' logs – Jordi Nebot Jan 5 '18 at 10:33
  • 1
    I would always use the war in tomcat in production – Ian Turton Jan 5 '18 at 10:39
  • 1
    I'll do that hopping that it works. I'll update/delete my question afterwards... Thanks! – Jordi Nebot Jan 5 '18 at 10:40
  • 1
    Hi @JordiNebot. I see what you're saying. I'll run some tests locally and get back to you here soon. – Alex Leith Jan 11 '18 at 22:27
4
+50

Try running it without the apache proxy first, that will rule out it being in the web server. You should be able to point to localhost:8000 in order to get to GeoServer directly.

The 405 error is unusual for GeoServer.

EDIT: Looking at the documentation, here, it seems that you should be using POST rather than PUT. Can you try that?

EDIT2: The documentation seems to be misleading, as, from testing, I can use PUT and not POST with the kind of URL you're using. But regardless, I've tested and this code works:

#!/usr/bin/env python3

import requests

shapefile = "/Users/alex/Desktop/example_shapefile.zip"
url = 'http://localhost:8080/geoserver/rest/workspaces/test_workspace/datastores/test_datastore/file.shp'

headers = {
    "Content-type": "application/zip"
}

with open(shapefile, 'rb') as data:
    r = requests.put(url, data=data, auth=('admin', 'geoserver'), headers=headers)

print(r.status_code, r.text)

I'm not sure what you're doing in PHP, but I certainly didn't get a 405 error when using PUT, though I did with a POST.

Note that I did get an error about 'magic numbers' if I didn't set the headers with the Content-type.

2

If you use the latest GeoServer then PUT is not for creating a new datastore. Use POST instead as documented in

http://docs.geoserver.org/latest/en/api/#/1.0.0/datastores.yaml

enter image description here

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.