HTTP Post request to Web Map Service...

Hi,

I'm trying to create a basic application which sends an xml-encoded GetCapabilities request to a Web Map Service. However, no WMS's will accept my xml. I don't know if this is a problem with my Java or my XML.

Could anyone tell me if I'm doing the HTTP Post wrong, or if my xml is wrong?

Thanks

Java code:

BufferedReader f =new BufferedReader(new FileReader("getCapabilities.xml"));

String l;

String body ="";

while((l = f.readLine()) !=null)

{

body = body + l;

}

System.out.println(body);

URL url =new URL("http://167.21.84.15/wmsconnector/com.esri.wms.Esrimap/DE_aerial02");

HttpURLConnection connection = (HttpURLConnection) url.openConnection();

connection.setRequestMethod("POST");

connection.setDoOutput(true);

connection.setDoInput(true);

PrintWriter writer =new PrintWriter(connection.getOutputStream());

writer.write(body);

writer.close();

InputStream in = connection.getInputStream();

BufferedReader b =new BufferedReader(new InputStreamReader(connection.getInputStream()));

String line;

while ((line = b.readLine()) !=null)

{

System.out.println(line);

}

XML request:

<wms:GetCapabilities service="WMS" version="1.0.0"

xmlns="http://www.opengis.net/wms"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wms/1.0.0/WMS-basic.xsd">

</wms:GetCapabilities>

[2294 byte] By [dead_passivea] at [2007-11-27 11:41:31]
# 1

Wha'ts a Web Map Service? How should we know what some server wants you to send it?

The POST'ing part of the code looks correct. But POST is generally going to be the same format as a GET request (name=value...), except the params are in the body instead of the URL. So unless the server explicitly accepts something else, then probably your input is wrong.

bsampieria at 2007-7-29 17:38:37 > top of Java-index,Java Essentials,Java Programming...
# 2

A WMS is an OGC standard specification for retrieving and displaying mays, it's specification is available online.

My question was aimed at people who might have had experience with WMS's in the past, only they could comment on my xml really (unless it's obviously malformed). The URL used in the code is just one of many I could use, for example there's a list here - http://www.skylab-mobilesystems.com/en/wms_serverlist.html

The whole point of my doing POST is so I can send XML documents to the service, otherwise I could just use KVPs as you said, but this limits what I can send.

Thanks for the help anyway.

Message was edited by:

dead_passive

dead_passivea at 2007-7-29 17:38:37 > top of Java-index,Java Essentials,Java Programming...