[Geoserver-users] [Geoserver users] PHP curl and WFS

Hello,

I am about to scream.

using this url directly in the browser:

localhost:8080/geoserver/wfs?request=getfeature&outputformat=csv&service=wfs&typename=Tan_regions&cql_filter=(tanzania:REGION
like 'Tanga')

yields exactly what I am out for.
But, alas...
passing it as an CURLOPT_URL to curl in PHP gives nothing. No error, no
warning and a ZERO-result.

The difference may have something to do with the CQL-Filter. changing
the url to:

localhost:8080/geoserver/wfs?request=getfeature&outputformat=csv&service=wfs&typename=Tan_regions

makes curl return the csv as expected.

Anyway, filtering is requested and I really *would like* to understand,
why the first works in the Browser but not with curl and the second one
(without the filter) does work when sent with curl.

Do I need to say, that in both cases the code for curl is exactly the same?

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
//Collect result.
$result = curl_exec($ch);
curl_close ($ch);

Please: if any body has a link to some documentation where I can read
about that issue, any hint to what is going on here would be most
appreciated....

best regards

HZN

The issue is probably that you're not encoding the parameters in your request, so you run into problems as soon as you try to use ":" or "(".

http://www.php.net/manual/en/function.curl-escape.php

If you have problems like this, you should set up a small PHP-script that just echoes what the server receives, and then run requests against that to spot differences in encoding etc.

-Arne

On 15/12/13 02:45 , Hartmut Noack wrote:

Hello,

I am about to scream.

using this url directly in the browser:

localhost:8080/geoserver/wfs?request=getfeature&outputformat=csv&service=wfs&typename=Tan_regions&cql_filter=(tanzania:REGION
like 'Tanga')

yields exactly what I am out for.
But, alas...
passing it as an CURLOPT_URL to curl in PHP gives nothing. No error, no
warning and a ZERO-result.

The difference may have something to do with the CQL-Filter. changing
the url to:

localhost:8080/geoserver/wfs?request=getfeature&outputformat=csv&service=wfs&typename=Tan_regions

makes curl return the csv as expected.

Anyway, filtering is requested and I really *would like* to understand,
why the first works in the Browser but not with curl and the second one
(without the filter) does work when sent with curl.

Do I need to say, that in both cases the code for curl is exactly the same?

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
//Collect result.
$result = curl_exec($ch);
curl_close ($ch);

Please: if any body has a link to some documentation where I can read
about that issue, any hint to what is going on here would be most
appreciated....

best regards

HZN

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Am 15.12.2013 11:35, schrieb Arne Kepp:

The issue is probably that you're not encoding the parameters in
your request,

You're a prince, Arne! That did the trick!

localhost:8080/geoserver/wfs?request=getfeature&outputformat=csv&service=wfs&typename=tanzania%3ATan_regions&cql_filter=%28tanzania:REGION
like %27Tanga%27%29

Works perfectly as expected.

so you run into problems as soon as you try to use ":" or "(".

Strange enough,that the result was returned OK when I appended
&layers=tanzania:Tan_regions The CSV came back OK, regardless of the
delimiter between workspace and layer name was *not* escaped. Maybe
that helped to obscure the real problem for me....
Further the geoserver website recommends some examples:

http://docs.geoserver.org/stable/en/user/services/wfs/vendor.html

these I copied and as you see, they are *not* escaped....

To be frank: the documentation is fair at best....

http://www.php.net/manual/en/function.curl-escape.php

Is not available in PHP 5.4 as we use it in Debian 7... Announced for
5.5. So I will have to do it by hand...

If you have problems like this, you should set up a small
PHP-script that just echoes what the server receives, and then run
requests against that to spot differences in encoding etc.

I take this as a hint, that URLs sent to geoserver should *always* be
build with escaped special-chars....

Lesson learned and
Apologies for asking something, that may be obvious around here :wink:

thanks a lot..

HZN

-Arne

On 15/12/13 02:45 , Hartmut Noack wrote:

Hello,

I am about to scream.

using this url directly in the browser:

localhost:8080/geoserver/wfs?request=getfeature&outputformat=csv&service=wfs&typename=Tan_regions&cql_filter=(tanzania:REGION

like 'Tanga')

yields exactly what I am out for. But, alas... passing it as an
CURLOPT_URL to curl in PHP gives nothing. No error, no warning
and a ZERO-result.

The difference may have something to do with the CQL-Filter.
changing the url to:

localhost:8080/geoserver/wfs?request=getfeature&outputformat=csv&service=wfs&typename=Tan_regions

makes curl return the csv as expected.

Anyway, filtering is requested and I really *would like* to
understand, why the first works in the Browser but not with curl
and the second one (without the filter) does work when sent with
curl.

Do I need to say, that in both cases the code for curl is exactly
the same?

curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch,
CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); //Collect result.
$result = curl_exec($ch); curl_close ($ch);

Please: if any body has a link to some documentation where I can
read about that issue, any hint to what is going on here would be
most appreciated....

best regards

HZN

------------------------------------------------------------------------------

Rapidly troubleshoot problems before they affect your business. Most IT

organizations don't have a clear picture of how application
performance affects their revenue. With AppDynamics, you get 100%
visibility into your Java,.NET, & PHP application. Start your
15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk

_______________________________________________

Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

------------------------------------------------------------------------------

Rapidly troubleshoot problems before they affect your business. Most IT

organizations don't have a clear picture of how application
performance affects their revenue. With AppDynamics, you get 100%
visibility into your Java,.NET, & PHP application. Start your
15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk

_______________________________________________

Geoserver-users mailing list Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

On Sun, Dec 15, 2013 at 1:50 PM, Hartmut Noack <zettberlin@anonymised.com>wrote:

Am 15.12.2013 11:35, schrieb Arne Kepp:
> The issue is probably that you're not encoding the parameters in
> your request,

You're a prince, Arne! That did the trick!

localhost:8080/geoserver/wfs?request=getfeature&outputformat=csv&service=wfs&typename=tanzania%3ATan_regions&cql_filter=%28tanzania:REGION
like %27Tanga%27%29

Works perfectly as expected.

> so you run into problems as soon as you try to use ":" or "(".

Strange enough,that the result was returned OK when I appended
&layers=tanzania:Tan_regions The CSV came back OK, regardless of the
delimiter between workspace and layer name was *not* escaped. Maybe
that helped to obscure the real problem for me....
Further the geoserver website recommends some examples:

http://docs.geoserver.org/stable/en/user/services/wfs/vendor.html

these I copied and as you see, they are *not* escaped....

These work in browsers because the browser is smart enough to escape
the chars automatically.

To be frank: the documentation is fair at best....

Eh, it's written by people that are not documentation professionals, often
in their spare time.
On the bright side, the documentation is open source too, so anybody
spotting space for improvement can spend some of their time to make
it better than they found it. Sources here:
https://github.com/geoserver/geoserver/tree/master/doc/en/user/source
Some docs about how to write docs here:
http://docs.geoserver.org/stable/en/user/

>
> http://www.php.net/manual/en/function.curl-escape.php

Is not available in PHP 5.4 as we use it in Debian 7... Announced for
5.5. So I will have to do it by hand...

>
> If you have problems like this, you should set up a small
> PHP-script that just echoes what the server receives, and then run
> requests against that to spot differences in encoding etc.

I take this as a hint, that URLs sent to geoserver should *always* be
build with escaped special-chars....

Any URL, to any server, must be escaped, it's a rule of the HTTP protocol.
It's just that most browsers automatically escape chars on your back
(they don't sent what you type, they fix it) so for normal users the issue
is transparent.
But when you start using a programming language, there is no automatism
anymore, you're supposed to know how a HTTP call works.
Believe we have all been there the first time, wondering why the request
worked in the browser, but not in our code.

Cheers
Andrea

--

Our support, Your Success! Visit http://opensdi.geo-solutions.it for more
information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

-------------------------------------------------------