IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Java Discussion :

Problème URL Connexion en HTTPs


Sujet :

Langage Java

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 57
    Par défaut Problème URL Connexion en HTTPs
    Bonjour,

    Je viens de mettre en place une connexion en http via HttpURLConnection.

    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
     
    		InputStream flux =null;
    		URL url = null;
    		HttpURLConnection  c = null;
     
    		try 
    		{
    			url = new URL("http://*******");
    			c = (HttpURLConnection) url.openConnection();
    			flux = c.getInputStream();
    		} catch (MalformedURLException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
     
    		for(int i=0; i<36; i++)
    		{
    			try {
    				messageId = messageId + (char)flux.read();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}	
    		}
     
    		try {
    			flux.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    Je voudrais maintenant faire un appel avec requete = "https://***********";

    J'ai essayer de remplacer les HttpURLConnection par HttpsURLConnection mais ça ne marche pas...

    Si quelqu'un pouvait m'aider... Merci d'avance pour votre aide...

  2. #2
    Expert éminent
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Billets dans le blog
    1
    Par défaut
    Salut,

    Citation Envoyé par lezert Voir le message
    mais ça ne marche pas...
    Chez moi ca marche...

    Enfin si on ignore la mauvaise gestion des exceptions, la boucle de lecture catastrophique et l'absence de try/finally pour la libération des ressources.


    a++

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 57
    Par défaut
    ok merci pour l'information...

    Juste une dernière précision, donc si je fais, ça, cela doit marcher ?

    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
     
    		InputStream flux =null;
    		URL url = null;
    		HttpsURLConnection  c = null;
     
    		try 
    		{
    			url = new URL("https://api.clickatell.com/http/auth?user=****&password=****&api_id=*****";");
    			c = (HttpsURLConnection) url.openConnection();
    			flux = c.getInputStream();
    		} catch (MalformedURLException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
     
    		for(int i=0; i<36; i++)
    		{
    			try {
    				messageId = messageId + (char)flux.read();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}	
    		}
     
    		try {
    			flux.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}

    Voila ce que j'obtiens de mon coté:

    java.net.ConnectException: Connection refused: connect

    Merci d'avance

  4. #4
    Expert éminent
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par lezert Voir le message
    Juste une dernière précision, donc si je fais, ça, cela doit marcher ?
    Il faut quand même corriger le code comme indiqué dans mon premier message.

    Citation Envoyé par lezert Voir le message
    Voila ce que j'obtiens de mon coté:

    java.net.ConnectException: Connection refused: connect
    Ah donc tu as une erreur !

    Le serveur te refuse la connexion.
    Maintenant pour savoir pourquoi c'est une autre histoire... Il faudrait te tourner vers les administrateurs de cette API...


    a++

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 57
    Par défaut
    Ok merci beaucoup pour ton aide, c'est sympa...

    Je poste juste mon erreur complète en cas que quelqu'un l'ai déjà eu...

    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
    java.net.ConnectException: Connection refused: connect
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    	at java.net.Socket.connect(Socket.java:519)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:550)
    	at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
    	at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
    	at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
    	at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
    	at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:271)
    	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:328)
    	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
    	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793)
    	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
    	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
    	at com.sms.ClickatelSmsCommunicator.sendMessage(ClickatelSmsCommunicator.java:97)
    	at com.services.DeviceMangerImpl.sendAMessage(Unknown Source)
    	at com.gui.MenuBar$ClientWarningListener$1.actionPerformed(Unknown Source)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    	at java.awt.Component.processMouseEvent(Component.java:6216)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    	at java.awt.Component.processEvent(Component.java:5981)
    	at java.awt.Container.processEvent(Container.java:2041)
    	at java.awt.Component.dispatchEventImpl(Component.java:4583)
    	at java.awt.Container.dispatchEventImpl(Container.java:2099)
    	at java.awt.Component.dispatchEvent(Component.java:4413)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
    	at java.awt.Container.dispatchEventImpl(Container.java:2085)
    	at java.awt.Window.dispatchEventImpl(Window.java:2475)
    	at java.awt.Component.dispatchEvent(Component.java:4413)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at com.sms.ClickatelSmsCommunicator.sendMessage(ClickatelSmsCommunicator.java:107)
    	at com.services.DeviceMangerImpl.sendAMessage(Unknown Source)
    	at com.gui.MenuBar$ClientWarningListener$1.actionPerformed(Unknown Source)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    	at java.awt.Component.processMouseEvent(Component.java:6216)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    	at java.awt.Component.processEvent(Component.java:5981)
    	at java.awt.Container.processEvent(Container.java:2041)
    	at java.awt.Component.dispatchEventImpl(Component.java:4583)
    	at java.awt.Container.dispatchEventImpl(Container.java:2099)
    	at java.awt.Component.dispatchEvent(Component.java:4413)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
    	at java.awt.Container.dispatchEventImpl(Container.java:2085)
    	at java.awt.Window.dispatchEventImpl(Window.java:2475)
    	at java.awt.Component.dispatchEvent(Component.java:4413)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Si quelqu'un pouvait me donner une adresse de type https avec lequel il n'y a pas de problème de connetion en utilisant mon code qui est donc fonctionnel...

    Merci beaucoup pour votre aide à tous et surtout à toi adiGuba

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème URL état HTTP 404
    Par kanebody dans le forum Spring
    Réponses: 2
    Dernier message: 14/11/2013, 10h25
  2. Apache http problème de connexion Exchange
    Par Lordrem dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 07/08/2012, 16h16
  3. Problème de connexion au HTTPS
    Par siempre dans le forum Windows XP
    Réponses: 6
    Dernier message: 13/07/2012, 18h34
  4. Connexion à une URL avec authentification HTTP en python 3.2
    Par Jean-Pascal dans le forum Réseau/Web
    Réponses: 2
    Dernier message: 31/03/2011, 16h03
  5. problème de connexion 2 PC
    Par guitalca dans le forum Développement
    Réponses: 3
    Dernier message: 22/09/2003, 14h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo