Salut!
voici mon code (en particulier ligne 54)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package net.zxq.andrelect.test;
 
import android.app.Activity;
import android.os.Bundle;
import org.apache.http.NameValuePair;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
//import org.apache.http.NameValuePair;
//import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
//import org.apache.http.message.BasicNameValuePair;
//import org.apache.http.params.HttpConnectionParams;
//import org.apache.http.protocol.HTTP;
import java.io.*; //io exceptions
import java.net.MalformedURLException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.InputSource;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import org.w3c.dom.Document;
import android.widget.TextView;
public class XMLTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        String xml = getXML();
 
        /*Document doc = XMLfromString(xml);*/
        TextView tv = new TextView(this);
        //tv.setText(doc.toString());
        tv.setText(xml.toString());
        setContentView(tv);
        }
    public static String getXML(){
    		String line = null;
    		try {
    			DefaultHttpClient httpClient = new DefaultHttpClient();
    			HttpPost httpPost = new HttpPost("http://andrelect.zxq.net/test.php");
    			HttpResponse httpResponse = httpClient.execute(httpPost);
    			HttpEntity httpEntity = httpResponse.getEntity();
    			line = httpEntity.toString();
    		} catch (UnsupportedEncodingException e) {
    			line = " erreur 1";
    		} catch (MalformedURLException e) {
    			line = "erreur 2";
    		} catch (IOException e) {
    			line = "erreur 3";
    		}
    		return line;
    }
 
public Document XMLfromString(String xml){
 
 
 
    Document doc = null;
 
 
 
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 
        try {
 
 
 
        DocumentBuilder db = dbf.newDocumentBuilder();
 
 
 
        InputSource is = new InputSource();
 
            is.setCharacterStream(new StringReader(xml));
 
            doc = db.parse(is);
 
 
 
        } catch (ParserConfigurationException e) {
 
            System.out.println("XML parse error: " + e.getMessage());
 
            return null;
 
        } catch (SAXException e) {
 
           System.out.println("Wrong XML file structure: " + e.getMessage());
 
            return null;
 
        } catch (IOException e) {
 
            System.out.println("I/O exeption: " + e.getMessage());
 
            return null;
 
        }
 
 
 
        return doc;
 
 
 
    }
 
}
j'ai comme résultat "erreur 3", ce qui signifie qu'une erreur IOException est levée: où est le problème? sachant que je peux accéder sans problème à cet URL via le navigateur.
Merci d'avance.