gpt4 book ai didi

post - 如何通过 POST 正确请求地理服务器 WFS?

转载 作者:行者123 更新时间:2023-12-01 01:14:15 28 4
gpt4 key购买 nike

我有一个 geoserver例如,包含我们的数据。通过 GET 请求可以正常工作并返回预期结果。但遗憾的是它不适用于 POST。

准确地说,这是对带有 GET 的 Capabilities 的请求,它返回一个有效的 GetCapabilities-Response:

http://myserver:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities

我用 wget 对此进行了测试,因此命令如下所示:
wget -O wfs 'http://myserver:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities'

现在我尝试使用 POST 的 Capabilities-request。我创建一个包含以下内容的请求(命名请求)文件:
<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"/>

我使用以下 wget 对 Geoserver 运行:
wget -O wfs --post-file=request 'http://myserver:8080/geoserver/wfs'

但现在我得到一个 OWS-Exception:
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://moa:8080/geoserver/schemas/ows/1.1.0/owsAll.xsd">
<ows:Exception exceptionCode="MissingParameterValue" locator="request">
<ows:ExceptionText>Could not determine geoserver request from http request org.geoserver.platform.AdvancedDispatchFilter$AdvancedDispatchHttpRequest@1e5c2cc</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>

这看起来好像没有发送 POST-body 或者它被忽略了。我在这里做错了什么?

编辑 : 好的,我解决了这个问题。问题是 Geoserver 需要一个 Content-Type-Header 来发布 XML 文件。所以正确的请求如下所示:
wget -O wfs --header='Content-Type: text/xml' --post-file=request.xml 'http://myserver:8080/geoserver/wfs'

这将返回预期的结果。

最佳答案

我试图调查你的情况,但我没有服务器,所以我使用了 http://demo.opengeo.org/geoserver/web/

GET 测试: http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities
我和你一样得到了完整的回应。

POST 测试:我用过 http://www.hurl.it/因为我在 Windows 计算机上。具有以下参数:

  • 网址:http://demo.opengeo.org/geoserver/wfs
  • 参数:add body > 和你的一样:
  • <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"/>

    我得到了与 GET 版本相同的响应。

    你能用这个演示服务器尝试相同的测试吗?

    更新

    在聊了几句评论之后,OP 找到了自己的解决方案。 POST 调用缺少必需的 Content-Type-Header 信息。

    关于post - 如何通过 POST 正确请求地理服务器 WFS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24952960/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com