Bonjour ,
etant débutant en android , je cherche à réaliser la tache suivante :
Dans mon code java de mon activité principale j'ai fait ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 connexion au serveur : $ curl -c cookies.txt data "action=connect&login=toto&password=toto" openxum.org/android/index.php récupération du nombre max : $ curl -b cookies.txt openxum.org/android/index.php ?action=get_max sauvegarde du score : $ curl -b cookies.txt data "action=score&value=10" http ://openxum.org/android/index.php Ces tests vous permettent de voir les requêtes à réaliser. Loption data indique que la requête est au format POST. Les autres sont au format GET. 2
Mais je me prends une erreur 500. (Donc serveur ... )
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 if(connection == true){ String temp = null; HttpResponse response = null; Document doc = null; DefaultHttpClient client = new DefaultHttpClient (); HttpPost request = new HttpPost ("http://openxum.org/android/index.php"); List< NameValuePair > nameValuePairs = new ArrayList < NameValuePair >(); nameValuePairs.add( new BasicNameValuePair("action", "connect" )); nameValuePairs.add( new BasicNameValuePair("login", "toto")); nameValuePairs.add( new BasicNameValuePair("password", "toto")); try { request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { response = client.execute( request ); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { doc = builder.parse( response.getEntity().getContent ()); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Element root = doc.getDocumentElement(); if ( root.getNodeName().compareTo("status") == 0) { temp = root.getAttributes().getNamedItem("value").getNodeValue(); } }
Pouvez vous m'aider dans les étapes que j'ai décrite au dessus svp .
Merci
Partager