Bonjour,
J'aurais voulu savoir comme faire un appel en https.
En effet, la fonction suivante marche très bien en http (vous m'escuserez pour les exception qui sont mal géré pour le moment):
Code :
- requete ="http://api.clickatell.com/http/auth?user=*****&password=*****&api_id=******";
- InputStream flux =null;
- URL url = null;
- HttpURLConnection c = null;
- try
- {
- url = new URL(requete);
- c = (HttpURLConnection) url.openConnection();
- flux = c.getInputStream();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "";
- }
|
mais en https, j'ai une erreur:
Code :
- requete ="https://api.clickatell.com/http/auth?user=*****&password=*****&api_id=******";
- InputStream flux =null;
- URL url = null;
- HttpsURLConnection c = null;
- try
- {
- url = new URL(requete);
- c = (HttpsURLConnection) url.openConnection();
- flux = c.getInputStream();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "";
- }
|
Erreur:
Code :
- 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:101)
- at com.sms.main.main(main.java:9)
- Exception in thread "main" java.lang.NullPointerException
- at com.sms.ClickatelSmsCommunicator.sendMessage(ClickatelSmsCommunicator.java:111)
- at com.sms.main.main(main.java:9)
|
Quelqu'un pourrait m'aider sur ce problème car je cherche depuis plusieurs jour...
Merci d'avance.
Message édité par lezert le 09-03-2010 à 13:36:20