Apache Http Client 4.1: Inviare un file xml tramite POST

Ottenuto in qualche modo un oggetto valido HttpClient, il resto è:

HttpPost post = new HttpPost("http://localhost:8080/servlet...");
 
// Creo il file XML da inviare tramite post
xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?><... il mio file xml ..." ;
 
try {
 
	post.setEntity(new StringEntity(xml));
 
	HttpResponse response = httpclient.execute(post);
	HttpEntity entity = response.getEntity();	
 
	if (entity != null) {
		System.out.println(EntityUtils.toString(entity));
	}	    	
 
} catch (UnsupportedEncodingException e) {
	...
} catch (ClientProtocolException e) {
	...
} catch (ParseException e) {
	...
} catch (IOException e) {
	...
}

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>