Bonjour,

J'essaye desesperement de poster un String sous forme XML a un service web.

J'ai utilisé le site postcatcher.in pour mes tests, mon message et correctement envoyé et je reçois une réponse de confirmation sans problème.

MAIS lorsque j'essaye de le poster sur mon appli en local, rien ne fonctionne, je ne pense pas que se soit le pare feu car j'ai développé une autre appli en c# qui fait la même chose et ça fonctionne. Voici mon code:

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
 
public class MainActivity extends Activity {
                private String CLASS_TAG = "BenTests";
 
                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
 
        //String adress = "http://postcatcher.in/catchers/xxxxxxxxxxxx";
        String adress = "http://localhost/HealthDataServer/jsv/reply/Gateway_Acknowledgement";
 
        String message = "<Gateway_Acknowledgement xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.datacontract.org/2004/07/ServiceStack.Acknowledgement\"><Id>0</Id><acknowledgementFilename>test</acknowledgementFilename><acknowledgementSequenceid>test</acknowledgementSequenceid><gatewayinfoLocalid>test</gatewayinfoLocalid><gatewayinfoSessionid>test</gatewayinfoSessionid><gatewayinfoSoftwareversion>test</gatewayinfoSoftwareversion><gatewayinfoTimestamp>test</gatewayinfoTimestamp></Gateway_Acknowledgement>";
 
        new MyAsyncTask().execute(adress, message);
                }
 
 
    private class MyAsyncTask extends AsyncTask<String, Integer, Double>{
 
                                @Override
                                protected Double doInBackground(String... params) {
                                                // TODO Auto-generated method stub
                                                postData(params[0], params[1]);
                                                return null;
                                }
 
                                protected void onPostExecute(Double result){
                                                //pb.setVisibility(View.GONE);
                                                Toast.makeText(getApplicationContext(), "Command sent!", Toast.LENGTH_LONG).show();
                                }
 
                                public void postData(String adress, String message) {
 
                                                // Create a new HttpClient and Post Header
                                                HttpClient httpclient = new DefaultHttpClient();
                                                HttpPost httppost = new HttpPost(adress);
 
                                                try {
                                                                // Add your data
                                                                httppost.setEntity(new StringEntity(message.toString()));
 
                                                                // Add Headers
                                                                /*  For Test
                                                                //httppost.setHeader("Accept", "application/x-www-form-urlencoded; encoding='utf-8'");
                                                                //httppost.setHeader("Content-type", "application/x-www-form-urlencoded; encoding='utf-8'");
                                                                */
 
                                                                // To send XML file 
 
                                                                httppost.setHeader("Accept", "application/xml;");
                                                                httppost.setHeader("Content-type", "application/xml;");
                                                                httppost.setHeader("Accept", "length");
                                                                httppost.setHeader("Content-Length", "length");
 
                                                                // Execute HTTP Post Request
                                                                HttpResponse response = httpclient.execute(httppost);
                                                                String status = response.getStatusLine().toString();
                                                                // Get response messages
                                                                Log.d(CLASS_TAG + "showOnScreenMessage", "Message sent! ");
                                                                Log.d(CLASS_TAG + "showOnScreenMessage", "Status : " + status );
 
 
                                                } catch (ClientProtocolException e) {
                                                                // TODO Auto-generated catch block
                                                                //Toast.makeText(getApplicationContext(), "Message not sent!", Toast.LENGTH_LONG).show();
 
                                                } catch (IOException e) {
                                                                // TODO Auto-generated catch block
                                                }
                                }
                }
}
Avez vous idée s'il vous plait?