bonsoir j ai un petit problème d authentfication a un serveur wcs(webpshere) a distance , je vous montre mon code vous regarder si ya des erreurs car j arrive toujours pas a me connecter , je suis un debutant android et webservice
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
114
115
116
117
118
119
120
121
122
123
124
 
 
public class Authentification extends Activity {
    /** Called when the activity is first created. */
	  String  response ;
	final String username = "19851985";
	String result;
    final String password = "ddddd85";
 
    HttpResponse httpresponse;
	InputStream chaine;
 
    final String proxyHost = "http://10.0.2.2/webapp/wcs/boutique/servlet/Address?storeId=10101&catalogId=10101&langId=-2"; 
    final int proxyPort = 80; 
 
    String url="http://10.0.2.2/webapp/wcs/boutique/servlet/Address?storeId=10101&catalogId=10101&langId=-2";
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
   		nameValuePairs.add(new BasicNameValuePair("username ", username ));
   		nameValuePairs.add(new BasicNameValuePair("password ", password));
 
           DefaultHttpClient  client  = new DefaultHttpClient();
 
 
        	HttpEntity entity;
       	HttpPost httpGet = new 	HttpPost(url);
 
       	try {
			httpGet.setEntity(new UrlEncodedFormEntity(nameValuePairs));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
       httpGet.addHeader("User-Agent", "Android");
 
        	HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
 
			try {
				httpresponse = client.execute(httpGet);
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	entity = httpresponse.getEntity();
 
			try {
				chaine = entity.getContent();
			} catch (IllegalStateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				result = stream2String(chaine);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
 
			JSONArray jsonOrdArray = null;
			try {
				jsonOrdArray = new JSONArray(result);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
 
			for(int  i=0;i<jsonOrdArray.length();i++)
			{
				Order order = new Order();
				 JSONObject commande = null;
				try {
					commande = jsonOrdArray.getJSONObject(i);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				 try {
					order.reference= commande.getString("reference");
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
 
 
 
        }
 
 
    private String stream2String(InputStream stream)
	throws UnsupportedEncodingException {
String charSet = "iso-8859-1";
InputStreamReader reader = new InputStreamReader(stream, charSet);
 
BufferedReader buffer = new BufferedReader(reader);
StringBuilder sb = new StringBuilder();
try {
	String cur;
	while ((cur = buffer.readLine()) != null) {
		sb.append(cur);
	}
} catch (IOException e) {
	e.printStackTrace();
}
try {
	stream.close();
} catch (IOException e) {
	e.printStackTrace();
}
return sb.toString();
}
 
}