Bonjour
Je développes une application pour me connecter au Wifi de mon école.
Voici comment je dois procéder pour me connecter depuis un pc/ordi
1°) Ouvrir mon navigateur
2°) Accepter de comprendre les risques
3°) Et me connecter
Cependant, le certificat de l'école n'est pas "sur"
C'est à dire que je dois par exemple pour utiliser le wifi de mon école sur un ordi, ajouter une exception pour le navigateur Firefox et comprendre les risque sur Chrome.
Comment je peux faire pour "passer directement à l'étape d'après" c'est a dire de l'étape 1 -> 3 directement à la connexion et donc ne pas passer par l'étape certificats ou alors accepter automatiquement d'ajouter cette exception.
Actuellement avec mon application, l'erreur afficher est "no peer certificate"
Cf code
Code : Sélectionner tout - Visualiser dans une fenêtre à part MAIN ACTIVITY
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 package com.example.loginapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import java.util.ArrayList; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; @SuppressLint("NewApi") public class MainActivity extends Activity { EditText un, pw; TextView error; Button ok; private String resp; private String errorMsg; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); un = (EditText) findViewById(R.id.et_un); pw = (EditText) findViewById(R.id.et_pw); ok = (Button) findViewById(R.id.btn_login); error = (TextView) findViewById(R.id.tv_error); ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /** According with the new StrictGuard policy, running long tasks on the Main UI thread is not possible So creating new thread to create and execute http operations */ new Thread(new Runnable() { @Override public void run() { ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair("username",un.getText().toString())); postParameters.add(new BasicNameValuePair("password",pw.getText().toString())); String response = null; try { response = SimpleHttpClient.executeHttpPost("https://10.20.0.1:4100/logon.shtml", postParameters); //response = SimpleHttpClient.executeHttpPost("https://accounts.google.com/Login?hl=FR", postParameters); String res = response.toString(); resp = res.replaceAll("\\s+", ""); } catch (Exception e) { e.printStackTrace(); errorMsg = e.getMessage(); } } }).start(); try { /** wait a second to get response from server */ Thread.sleep(1000); /** Inside the new thread we cannot update the main thread So updating the main thread outside the new thread */ error.setText(resp); if (null != errorMsg && !errorMsg.isEmpty()) { error.setText(errorMsg); } } catch (Exception e) { error.setText(e.getMessage()); } } }); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part SimpleHttpClient
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 public class SimpleHttpClient { /** The time it takes for our client to timeout */ public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds /** Single instance of our HttpClient */ private static HttpClient mHttpClient; /** * Get our single instance of our HttpClient object. * * @return an HttpClient object with connection parameters set */ private static HttpClient getHttpClient() { if (mHttpClient == null) { mHttpClient = new DefaultHttpClient(); final HttpParams params = mHttpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT); HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT); ConnManagerParams.setTimeout(params, HTTP_TIMEOUT); } return mHttpClient; } /** * Performs an HTTP Post request to the specified url with the * specified parameters. * * @param url The web address to post the request to * @param postParameters The parameters to send via the request * @return The result of the request * @throws Exception */ public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception { BufferedReader in = null; try { HttpClient client = getHttpClient(); HttpPost request = new HttpPost(url); UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters); request.setEntity(formEntity); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String result = sb.toString(); return result; } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } /** * Performs an HTTP GET request to the specified url. * * @param url The web address to post the request to * @return The result of the request * @throws Exception */ public static String executeHttpGet(String url) throws Exception { BufferedReader in = null; try { HttpClient client = getHttpClient(); HttpGet request = new HttpGet(); request.setURI(new URI(url)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String result = sb.toString(); return result; } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
Partager