Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly request a geoserver WFS via POST?

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.

like image 503
Mnementh Avatar asked Oct 01 '22 06:10

Mnementh


1 Answers

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:

  • URL: http://demo.opengeo.org/geoserver/wfs
  • Parameters: add body > same as yours:

<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.

like image 197
Nicolas R Avatar answered Dec 25 '22 14:12

Nicolas R