Advertencia este el código tiene más de 5 años. Hice algunos modfying para esta publicación y nunca lo probé. Espero que ayude.
mensaje XML (datos) a un servidor y downlod la resp:
public int uploadToServer(String data) throws Exception {
OutputStream os;
URL url = new URL("someUrl");
HttpURLConnection httpConn= (HttpURLConnection) url.openConnection();
os = httpConn.getOutputStream();
BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(os));
osw.write(data);
osw.flush();
osw.close();
return httpConn.getResponseCode();
}
public String downloadFromServer()
throws MalformedURLException, IOException {
String returnString = null;
StringBuffer sb = null;
BufferedInputStream in;
//set up httpConn code not included same as previous
in = new BufferedInputStream(httpConn.getInputStream());
int x = 0;
sb = new StringBuffer();
while ((x = in.read()) != -1) {
sb.append((char) x);
}
in.close();
in = null;
if (httpConn != null) {
httpConn.disconnect();
}
returnString = sb.toString();
return returnString;
}
En algún otro lugar .....
int respCode = uploadToServer(someXmlData);
if (respCode == 200) {
String respData = downloadFromServer();
}
usando qué? httpclient, URLConnection? ¿A qué - una página web, un servicio web? Tu pregunta no está clara. – Bozho
lo siento ... ya sea httpclient o URLConnection .. Necesito mostrar la respuesta en una página web .. – shil
Actualice la pregunta con estos detalles. y dar un poco más: cuál es la página de destino y cómo espera el xml. Como un parámetro de post típico? – Bozho