I'm trying to build a web mapping app that retrieves data from our WFS server. I'd like to avoid JavaScript for the main search scripts.

From what's I've read the best way to send the XML POST request to the server is to use CURL.

I have tested the following very simple XML in GeoServer and it's fine. Hwever, when I send the request as below I get an error.

I have trawled Google but can't seem to find any examples of doing this. I can't believe I'm the only one trying to do this!

The PHP Code:

//Set variables.
$url = "http://squirrel.bis.local:8080/geoserver/wfs";
$post = '<GetCapabilities 
    xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0    /wfs.xsd"/>';

$post = str_replace("\r", "", $post); //Clean string.
$post = str_replace("\n", "", $post);
$post = str_replace("\t", "", $post);
$post = str_replace("> <", "><", $post); //Clean any leading spaces between elements.

//What are we sending?
echo "Post Request:<br />";
echo htmlentities($post);
echo "<br /><br />";

//Send post request.
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

//Collect result.
$result = curl_exec($ch);
curl_close ($ch);

//What did we get?
echo "Post Response:<br />";
echo "<pre>" . htmlentities($result) . "</pre>";
echo "<br /><br />";


The error is:

<ows:ExceptionReport version="1.0.0"
http://squirrel.bis.local:8080/geoserver/schemas/ows/1.0.0                   /owsExceptionReport.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:ows="http://www.opengis.net/ows">
<ows:Exception exceptionCode="MissingParameterValue" locator="request">
<ows:ExceptionText>Could not determine geoserver request from http request         org.geoserver.platform.AdvancedDispatchFilter$AdvancedDispatchHttpRequest@19f0b0a6

Thanks Steve

2 Answers 2


You have to make sure to set the HTTP Content-Type/Content-Length headers:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Content-Length: '.strlen($post)));

In this case, the value of Content-Length would be the size of your XML request.

  • Job done! Working perfectly!! Thanks you very much for your help!
    – user8262
    Jun 21, 2012 at 8:40

You need to check what is actually sent to the server but I suspect you have deleted all the white space between the attributes in your request so it looks something like

<GetCapabilitiesservice="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"/>

If I'm right then try (replace \t etc with space):

$post = str_replace("\r", " ", $post); //Clean string.
$post = str_replace("\n", " ", $post);
$post = str_replace("\t", " ", $post);
  • Checked this and I don't think it's the issue. I was careful to add a trailing space at the end of each line of XML in case this happened. I have added the space as suggested and the response is the same. The string being sent is: <GetCapabilities service="WFS" xmlns="opengis.net/wfs" xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:schemaLocation="opengis.net/wfs schemas.opengis.net/wfs/1.1.0/wfs.xsd">
    – user8262
    Jun 20, 2012 at 13:15
  • are there really ; in there between the lines? if so that's the problem.
    – Ian Turton
    Jun 20, 2012 at 13:55
  • No - that's just someting that's crept in during copy and paste!
    – user8262
    Jun 21, 2012 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.