XML vs KVP request to WFS

I understand how KVP requests are transmitted via HTTP to a WFS, but the WFS spec says the request may be encoded in XML. I have 2 questions:

1) Is the WFS [b]required [/b]to support XML [b]and [/b]KVP requests?

2) How is an XML-formatted request delivered to the WFS?

XML vs KVP request to WFS


creed's picture

XML vs KVP request to WFS

Cool. Thanks. Can I pass this info onto the OGC membership?


XML vs KVP request to WFS

While researching this problem I came across a way to send a POST message with an XML body from a web page using Javascript, which might be useful for testing. It doesn't require any server-side deployment to set up. It uses a Javascript XMLHttpRequest object to send the message. Here's a simple example:


PLworks WFS test page

onmousedown="return loadXMLDoc('');">Send XML POST



Thank you, Carl. That was above and beyond!

I was being too browser-centric. [i]Q: How do you send an XML post directly from an HTML form? A: [u]You can't[/u].[/i] That clears it up! I hope others just getting started will benefit from that information, too.

creed's picture

XML vs KVP request to WFS

Sorry for the delay in responding. Here is some information that may be of use. It was provided by one of the OGC WFS gurus.

Hope this helps.

POST and GET can both send KVP encoded requests to your wfs, but using
different mechanisms.

The understand the difference you need to look at both the browser side
and the server side.

First, keep the form of the FORM element in mind:



When you use the GET method, your browser creates a URL using the value
of the ACTION attribute and all the input fields in your form:


You browser then sends this URL to the target web server using the GET

At the server end, your httpd process (apache for example) processes
this URL by setting an environment variable, called QUERY_STRING, with
everything after the '?'. So the value of QUERY_STRING is:


Your web server also invokes the handler process (your wfs server). The
wfs then reads the QUERY_STRING environment variable, processes the KVPs
and send its response back to the rowser via your web server.

This is what happens in a standard CGI implementation. In other
implementations, PHP, servlets, etc ... similar things happen but the
HTTP mechanisms are more obfuscated (although perhaps more convenient
way for the programmer) so that the programmer does not need to read the
environment directly or parse the KVP string directly. This, instead,
is done automatically and presented in a convenient way.


When you use the POST METHOD in an HTTP form, your browser creates a
document of MIME type application/x-www-form-urlencoded and sends it to
the wfs specified by the ACTION attribute using the HTTP POST method.
The document is basically a text file containing your form's input field
names and values encoded as KVPs.

Your web server (apache for example) simply streams the document to your
WFS and sets a bunch of environment variables indicating the content
type (application/x-www-form-urlencoded) the content length, etc ...

It is up to your wfs to recognize the mime type of the document and
process it accordingly. Notice that in this case, your wfs need to read
the mime type of the content and know how to unpack an
application/x-www-form-urlencoded document.

OK, now about XML encoded requests ...

You cannot do the same with an XML encoded request. In that case your
form would need to invoke and intermediate process (cgi, servlet, etc
...) that takes your XML request and posts it to the wfs that you
specify. The following is an example of this:


The XML you enter into the main field is read by the cwpost.cgi
application and posted to the server you specify in the server field.
The response from the server is read by cwpost.cgi and returned to your
browser via your web server.

XML vs KVP request to WFS

Thanks so much for your help. I have been looking at the WFS spec, but I think I am having a little trouble with the underlying web technology. This is probably a real newbie question:

[color=darkblue]Can I send an XML request from a web page I am using to test my WFS, or do I need a JSP or servlet to convert the KVPs to XML and then forward the request to the WFS? I thought that when I POSTed from an HTML form, I was getting key-value pairs just like when I used GET.[/color]

I hope someone can clarify this for me.

XML vs KVP request to WFS

The information you're asking for is defined in the WFS specification (OGC document 02-058).

1) As far as I know, a WFS server should accept both XML and KVP. I've looked through the standard in order to find a clear statement, but couldn't find one. It is most common to send XML formatted requests, instead of KVP requests. But if you really need KVP requests, then chapter 13 will contain all information.
If you're building a client, then I guess you're free to choose the way you like most, but I'd recommend to use XML.

2) If your request is in KVP, then it should be delivered with the HTTP GET method (query string in URL). If your request is in XML, then it should delivered with the HTTP POST method (URL-encoded post body). This is described in section 6.5 and at the end of section 12.3.4.

Good luck!