Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1484 connectés 

  FORUM HardWare.fr
  Programmation

  [JAVA] HttpURLConnection

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[JAVA] HttpURLConnection

n°88484
Tricky
En tapinant.
Posté le 11-01-2002 à 20:05:12  profilanswer
 

voilà une partie de mon code:
try
{    
  connectionn = (HttpURLConnection)monUrl.openConnection();
  try
  {
    responseCode = connectionn.getResponseCode();
    System.out.println(responseCode);
  }
  catch(IOException e)
  {
    System.out.println("Connexion impossible:getResponseCode" );        
  }    
}    
le probleme est que monUrl contient un truc bidon genre www.multimania.com/gnagnagna, le programme part dans le catch(IOException) alors que je m'attendais à un retour du code 404 de la part de getResponseCode() !!!!!!
 
Quelqu'un peut m'aider please ????

mood
Publicité
Posté le 11-01-2002 à 20:05:12  profilanswer
 

n°88487
darklord22
Nightwish rulezzzzzzzzzzzzz
Posté le 11-01-2002 à 20:27:08  profilanswer
 

J'ai eu le même problème que toi en son temps. Une solution très bourine mais qui fonctionne c'est de faire un truc du genre:
 

Code :
  1. /**
  2.  * Checks wheter this file exists or not
  3.  * This should avoid requests on a 404  
  4.  * Warning this method can decrease the performance
  5.  * 0,1 sec per file with good network performance
  6.  * @ param f
  7.  * The file to check
  8.  * @return true if the file exists
  9.  */
  10. private boolean validFile(WebFile f) {
  11.  long start = new Date().getTime();
  12.  try {
  13.   URL u = new URL(f.getURL());
  14.   HttpConnectionTools t = new HttpConnectionTools(u);
  15.   if (t.isOK())
  16.    return true;
  17.   else
  18.    return false;
  19.  }
  20.  catch (IOException e) {
  21.   Logger.debug(
  22.    this,
  23.    "Verifying "
  24.     + f.getURL()
  25.     + " failed ! done in "
  26.     + (new Date().getTime() - start)
  27.     + " msec" );
  28.   return false;
  29.  }
  30. }


 
A+


---------------
What is popular is not always right, what is right is not always popular :D

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  [JAVA] HttpURLConnection

 

Sujets relatifs
[java] lire une webcam?[java] convertir un Integer en binaire complément a 2 ?
[JAVA] probleme pour signer l'applet eirc ?[java] aidez moi a repondre a ces questions (tres rapide)
[JAVA] méthode pour afficher une JLIST au dessus du Panel[JAVA] Question de débutant : notion de "static"
[Java] Comment déplacer automatiquement le curseur ?[JAVA] Castor
reponse pour les APPLET JAVA !!!!apprentissage java
Plus de sujets relatifs à : [JAVA] HttpURLConnection


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR