Bonjour,
je cherche un exemple android pour appeler un web service.
J'ai à dispo un webservice sous php5, mais je n'arrive pas à trouver d'exemple android.
merci de votre participation
Version imprimable
Bonjour,
je cherche un exemple android pour appeler un web service.
J'ai à dispo un webservice sous php5, mais je n'arrive pas à trouver d'exemple android.
merci de votre participation
Il existe des libs pour appeller des WS depuis Android, mais ce n'est pas la technique recommandée par Google. En effet les WS sont consommateur de temps surtout pour ce type de plateforme. La technique recommandée est (je crois) du REST / JSON.
jahbromo > je suis repassé sur ton site. Mais je n'ai rien trouvé, as tu eu le temps de le remettre
merci
Salut,
Voici un morceau de code pour faire un appel a un webservice :
il reste juste a faire ton propre Handler pour deserialiser le Xml.Code:
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;
@+