How to correctly request a geoserver WFS via POST?

12.2k views Asked by At

I have a geoserver instance, that contains our data. Requesting this via GET works all-right and returns the expected results. But sadly it doesn't works with POST.

To be precise, here is the request for the Capabilities with GET, that returns a valid GetCapabilities-Response:

http://myserver:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities

I test this with wget, so the command looks like that:

wget -O wfs 'http://myserver:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities'

Now I try the Capabilities-request with POST. I create a file with the request (named request) with the following content:

<GetCapabilities
 service="WFS"
 xmlns="http://www.opengis.net/wfs"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.opengis.net/wfs
 http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/>

This I run against the Geoserver with the following wget:

wget -O wfs --post-file=request 'http://myserver:8080/geoserver/wfs'

But now I get an OWS-Exception:

<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://moa:8080/geoserver/schemas/ows/1.1.0/owsAll.xsd">
  <ows:Exception exceptionCode="MissingParameterValue" locator="request">
    <ows:ExceptionText>Could not determine geoserver request from http request org.geoserver.platform.AdvancedDispatchFilter$AdvancedDispatchHttpRequest@1e5c2cc</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

This looks like no POST-body has been sent or it was ignored. What do I wrong here?


EDIT: OK, I solved the problem. The problem is Geoserver expects a Content-Type-Header for Posting a XML-File. So correct request looks like the following:

wget -O wfs --header='Content-Type: text/xml' --post-file=request.xml 'http://myserver:8080/geoserver/wfs'

This returns the expected result.

1

There are 1 answers

17
Nicolas R On

I tried to investigate in your case but I don't have a server, so I used http://demo.opengeo.org/geoserver/web/

GET test: http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities

I got a full response like you did.

POST test: I used http://www.hurl.it/ because I am on a Windows computer. With the following parameters:

<GetCapabilities service="WFS" xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/>

And I got the same response as the GET version.

Can you try the same tests with this demo server?


UPDATE

After a few comments chatting, the OP find himself the solution. The POST call was missing the Content-Type-Header information which is mandatory.