1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://tonserveur/Service1.asmx/GetProduct");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("param", param));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
InputStream is = response.getEntity().getContent();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
String text = new String(baf.toByteArray());
ByteArrayInputStream xmlParseInputStream = new ByteArrayInputStream(
text.getBytes());
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parseur = factory.newSAXParser();
myProduct = new Product();
ProductHandler productHandler = new ProductHandler();
parseur.parse(xmlParseInputStream, productHandler);
return productHandler.myProduct; |
Partager