How to correctly request a geoserver WFS via POST?
Asked Answered
I

1

6

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.

Iiette answered 25/7, 2014 at 9:55 Comment(0)
L
4

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.

Lancashire answered 28/7, 2014 at 21:12 Comment(17)
wget -O wfs --post-file=request.xml 'demo.opengeo.org/geoserver/wfs' results in a similar OWS-ExceptionIiette
And this is no answer, why is it not a comment?Iiette
So maybe your syntax/tool is incorrect? You got good results with the web sit?Lancashire
So what is wrong with this wget-call? I stumbled into this problem while programming and used wget because it is a standard-tool and hence the error lies something on my side (request, url, wget-params, Geoserver-config, whatever). And my question was already in the original post: what do I wrong. You replicated this question.Iiette
Ok a few points: this is an answer because a comment is restricted in terms of characters. I tried to help you to proceed with your error, if I got an instant solution I will already bring it. As far as I know, you are stuck with something which is happening only with your wget tool, whatever the server is. And you don't have to be offensive, it will not help.Lancashire
Don't be offended. I try to solve the problem. As I told, I encountered the problem with programming and was reducing and encircling the problem, hence the wget. I can reproduce it with hurl, so the question is what hurl does differently. Maybe as it is executed by the browser this adds some headers, but which headers will be added? Whatever is the difference at what hurl does additionally is the deciding factor here, as whatever it does (additional headers for instance) could be added to wget and to my program. But I need to know what it is.Iiette
So next step you could try to find a basic POST demo service (not geoserver) and try basic call that have the same behaviour between your wget tool and hurl, then you may be able to see the difference in the data sent?Lancashire
wget isn't my tool, that's why I have chosen it. It is standard. I use it to avoid any other errors in other programs, because wget does correct http since many years, so I can pinpoint the problem towards the details of the request. en.wikipedia.org/wiki/Wget I don't see, inhowfar requesting another service would help, as it is obvious, that I do wrongly request the Geoserver, but the point is I don't know what I do wrong. I already know wget does correct post-request, as this tool did it millions of times for thousands of users.Iiette
I knew that wget is a standard tool, I said "your" because I don't have it. I suggested to try a basic service to validate the way you use your parameter file wiwh wget. Now if you are sure you did it in the right way...Lancashire
Hum... And what if wget cannot be used for passing POST parameters like you did? If these answers are still correct, it might be the problem: https://mcmap.net/q/209865/-post-request-with-wget & #12662259Lancashire
I updated my answer by using curl, as wget seems not to be the right tool (see previous comment)Lancashire
I don't mix post-file and post-data, that is the problem in both questions and I don't want to upload a file but use the content of the file as post-body.Iiette
Did you read the updated answer? I did not say you were using both parameters. You tried wget --post-file, which is intended to post the data of the file, but as the man page said: they both expect content of the form "key1=value1&key2=value2", with percent-encoding for special characters and it is not your case, isn't it?Lancashire
wget and --post-file isn't the problem, I updated my question, I found the solution.Iiette
perfect, so basically just a syntax (and filename missing an extension) problem! Just for my info, is it working with curl? With $ curl -X POST -d @request http://myserver:8080/geoserver/wfs or $ curl -X POST -d @request.xml http://myserver:8080/geoserver/wfsLancashire
curl is pretty much a similar tool to wget, so your command-line is giving me the same exception (I tried it), but it also allows to add the header-Option, and that works. It is the same as wget.Iiette
Ok thanks for the feedback. I cleaned the answer for visibilityLancashire

© 2022 - 2024 — McMap. All rights reserved.