Bonjour tout le monde,

afin de tester si un serveur HTTP n'est pas en panne ou arrêté, je désire effectuer un GET sur une url de ce serveur je fais donc la fonction :

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
 
	public boolean test() {
 
		try {
			InetAddress ia = InetAddress.getByName(inter.address);
 
			/** creation of a socket with the url and the http port by default*/
			Socket s = new Socket(urlGetHttp,80,ia,0); 
 
			s.setSoTimeout(10000);
 
			/** allows to create an entry flow on the socket to the customer */ 
			InputStream in = s.getInputStream(); 
 
			/** allows to create an exit flow on the socket to the server */
			OutputStream out = s.getOutputStream(); 
 
			/** allows to read the messages on the socket from the server */
			BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 
 
			/** allows to write on the exit flow */
			PrintWriter writer = new PrintWriter(out); 
 
			/** send the command to have informations from the server*/
			String command = "OPTIONS / HTTP/1.0\n\n"; 
			writer.print(command); 
			writer.flush(); 
 
			/** reads the response */
			String[] input = reader.readLine().split(" ");
 
			/** if the response contains an HTTP error code */
			if (Integer.parseInt(input[1])>=500) {				
				return false;
			}
 
			/** socket closed */
			s.close();
			return true;
 
		}catch (IOException e) {
			e.printStackTrace();			
			return false;
		}
	}
quand je passe comme url "intranet" il n'y pas de pb par contre si je lui passe par exemple "www.développez.com" ça ne marche pas et une exception est levée à la création de la Socket.

Qu'en pensez-vous svp?

Merci d'avance pour vos futures réponses !!!