Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

<?php 
//Set variables.
$url = "http://squirrel.bis.local:8080/geoserver/wfs";
$post = '<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"/>';

$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);
$content=curl_exec($ch);

//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"
xsi:schemaLocation="http://www.opengis.net/ows 
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
</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>

Thanks Steve

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Job done! Working perfectly!! Thanks you very much for your help! –  user8262 Jun 21 '12 at 8:40
add comment

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);
share|improve this answer
    
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 '12 at 13:15
    
are there really ; in there between the lines? if so that's the problem. –  iant Jun 20 '12 at 13:55
    
No - that's just someting that's crept in during copy and paste! –  user8262 Jun 21 '12 at 13:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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