The body of an http request can be coded in three ways :
- Can be one of form (application/x-www-form-urlencoded) ;
- multipart :multipart/form-data) ;
- or json (application/json).
For long cql_filter in geoserver, form body is used.
An example below for R users with IGN WFS geoserver
library(httr2) # perform http request
library(sf) # work with spatial features
apikey <- "administratif"
layer_name <- "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune"
# Param for creating url
params <- list(
service = "WFS",
version = "2.0.0",
request = "GetFeature",
outputFormat = "json",
srsName = "EPSG:4326",
typeName = layer_name
)
filter <- "INTERSECTS(the_geom, POLYGON ((47.94371 -4.315395, 47.80732 -4.309902, 47.8774 -4.103909, 47.94739 -3.939114, 48.18246 -3.9501, 48.01729 -4.27969, 47.94371 -4.315395)))"
# construct request
request <- request("https://wxs.ign.fr") |>
req_url_path_append(apikey) |>
req_url_path_append("geoportail/wfs") |>
req_url_query(!!!params) |>
req_body_form(cql_filter=filter)
# perform request
resp <- req_perform(request) |>
resp_body_string()
# read features
features <- read_sf(resp)