My WFS POST does not work.
Q: When I send a a WFS request to GeoServer through my Java application, I just get errors.
There are a couple errors you can get, but in general the problem is URL encoding.
What you need to make sure is that the content-type is application/xml.
Example:
url = new URL("http://localhost:8080/geoserver/wfs"); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/xml"); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true);
Where conn is your connection.
A user suggested the following code snippit:
try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod( url ); method.setFollowRedirects( true ); // Execute the GET method int statusCode = client.executeMethod( method ); if( statusCode != -1 ) { String contents = method.getResponseBodyAsString(); method.releaseConnection(); System.out.println( contents ); } } catch( Exception e ) { e.printStackTrace(); }
For further reading please head to this page.