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