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

Bibliothèques et frameworks PHP Discussion :

[Web Service] [PHP - SOAP - SSL]Could not connect to host


Sujet :

Bibliothèques et frameworks PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2009
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2009
    Messages : 2
    Par défaut [Web Service] [PHP - SOAP - SSL]Could not connect to host
    Bonjour,

    Je me permets de poster car cela fais des heures que je tourne en rond sur ce problème, et un regard neuf sur mon problème ne ferait pas de tord. Et que je suis bientôt prêt à abandonner PHP pour passer à Java : p.

    Je suis étudiant en sciences informatique et pour le moment en stage chez Vodafone Allemagne, dans un département IT B2B

    La problématique :
    Un serveur SOAP est en place et opérationnel, il possède toute une série de services auxquelles je tente d'accéder par l'intermédiaire d'un serveur PHP. Je travaille en local avec un serveur WAMP où j'ai bien activé mes extensions Soap, cURL et openSSL.

    La connexion au serveur se fait en https://, cela requiert donc l'acceptation de son certificat (périmé en plus :/).

    De plus, un certificat côté client est également demandé, avec un passphrase pour ce dernier.

    Ce qui fait que je dois jouer avec deux certificats : Un coté serveur et un coté client.

    J'ai trouvé une solution à ma problématique ici , que j'ai largement plagié.

    Voici le code PHP (purgé des données et variables sensibles, désolé : ))
    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
     
    <?php 
    $wsdl = "fichier.wsdl";
    $location = "https://...:20575";
    $certsClient = "C:\wamp\www\vodafone\keys.pem";
    $passPhraseClient = "...";
    $certsServeur = "C:\wamp\www\vodafone\CERT.pem";
     
    $context = stream_context_create(array("ssl" => array("verify_peer" => true,"cafile" => $certsServeur)));
     
    $client = new SoapClient($wsdl,array("trace" => 1,"soap_version" => SOAP_1_1,"location" => $location,"local_cert" => $certsClient,'passphrase' => $passPhraseClient,"stream_context" => $context));
     
    $client->leNomDuneFonction(array("..." =>"...","..." => "..."));
     
    ?>
    Qui me retourne un beau

    Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in C:\wamp\www\vodafone\soapclient.php

    Alors qu'une version similaire en Java fonctionne, elle :
    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
     
    public class ACRConverter {
     
    	public final static String DEFAULT_SERVER = "https://...:20575";
    	public final static String SOAP_ACTION = "...";
    	public final static String CLIENT_CERTIFICATE = "C:\\wamp\\www\\vodafone\\Test_Partner_PreProd_Certificate.pfx";
    	public final static String CLIENT_CERTIFICATE_PASSWORD = "...";
    	public final static String ACR_INPUT_FILE = "C:\\wamp\\www\\vodafone\\ACRs.txt";
    	public final static String MSISDN_OUTPUT_FILE = "C:\\wamp\\www\\vodafone\\MSISNDs.txt";
     
    	private static SSLSocketFactory getFactory(File pKeyFile, String pKeyPassword) throws Exception {
    		KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
    		KeyStore keyStore = KeyStore.getInstance("PKCS12");
     
    		InputStream keyInput = new FileInputStream(pKeyFile);
    		keyStore.load(keyInput, pKeyPassword.toCharArray());
    		keyInput.close();
     
    		keyManagerFactory.init(keyStore, pKeyPassword.toCharArray());
     
    		SSLContext context = SSLContext.getInstance("TLS");
    		context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
     
    		return context.getSocketFactory();
    	}
     
    	public static void main(String[] args) {
     
    		String server = DEFAULT_SERVER;
     
    		try {
     
    			// open parameter file
    			FileInputStream fstream = new FileInputStream(ACR_INPUT_FILE);
    			DataInputStream input_file_in = new DataInputStream(fstream);
    			BufferedReader br = new BufferedReader(new InputStreamReader(input_file_in));
     
    			// Open output file for responses
    			BufferedWriter output_file_out = new BufferedWriter(new FileWriter(MSISDN_OUTPUT_FILE));
     
    			// Prepare connection to service
    			URL url = new URL(server);
     
    			// Read File Line By Line
    			String s;
    			while ((s = br.readLine()) != null) {
     
    				System.out.println(s);
     
    				HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
    				connection.setSSLSocketFactory(getFactory(new File(CLIENT_CERTIFICATE), CLIENT_CERTIFICATE_PASSWORD));
     
    				connection.setDoOutput(true);
    				connection.setDoInput(true);
    				connection.setRequestMethod("POST");
    				connection.setRequestProperty("SOAPAction", SOAP_ACTION);
     
    				OutputStream out = connection.getOutputStream();
    				Writer wout = new OutputStreamWriter(out);
     
    				// Send request
     
    				wout.write("<soapenv:Envelope xmlns:v=\"http://...\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">");
    				wout.write("<soapenv:Header/>");
    				wout.write("<soapenv:Body>");
    				wout.write("<v:...");
    				wout.write("<v:...><![CDATA[" + ... + "]]></v:...>");
    				wout.write("</v:...>");
    				wout.write("</soapenv:Body>");
    				wout.write("</soapenv:Envelope>");
     
    				wout.flush();
    				wout.close();
     
    				// Get response
    				InputStream in = connection.getInputStream();
    				int c;
    				while ((c = in.read()) != -1) {
    					output_file_out.write(c);
    				}
    				in.close();
     
    				// Wait a second to reduce load
    				Thread.sleep(1000);
    			}
     
    			// Close the file with ACR list
    			input_file_in.close();
     
    			// Close the file with the MSISDNs
    			output_file_out.close();
     
    		} catch (Exception e) {
    			System.err.println(e);
    		}
     
    	}
     
    }
    Et les envois avec SoapUI fonctionnent également.

    Qu'ai-je fait de mal : (

    EDIT : Testé également sur un dédié perso et sur un hébergement mutualisé OVH, rien n'y fait, toujours la même erreur.

  2. #2
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2009
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2009
    Messages : 2
    Par défaut
    Solved.

    (C'est toujours après qu'on aie posé la question qu'on trouve la réponse).

    Je ne passe plus par un stream_context_create mais donne directement dans le constructeur du client SOAP le certificat du serveur, la clé du client et son pass

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    $wsdl = "fichier.wsdl";
    $location = "...:20575";
    $certsClient = "keys.pem";
    $passPhraseClient = "...";
    $certsServeur = "cert.cer";
     
    $client = new SoapClient($wsdl,array("trace" => 1,"soap_version" => SOAP_1_1,"location" => $location,"local_cert" => $certsClient,'passphrase' => $passPhraseClient));
     
    $client->leNomDuneFonction(array("..." =>"...","..." => "..."));
    Le pire c'est que j'ai quasi rien changé. Merci la perte de temps.

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

Discussions similaires

  1. [Web Service] SOAP-Uncaught SoapFault exception: [HTTP] Could not connect to host
    Par manaboko dans le forum Bibliothèques et frameworks
    Réponses: 8
    Dernier message: 14/05/2012, 09h52
  2. [Web Service] Php, SOAP et arguments
    Par CaviarNAS dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 27/09/2010, 11h57
  3. [Web Service] Php, Soap, SSL, Proxy => Could not connect to host
    Par madevilts dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 02/12/2009, 15h52
  4. [Web Service] PHP, soap et type complex
    Par Invité dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 01/07/2009, 16h58
  5. [Web Service] PHP & SOAP - web service
    Par Gregory.M dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 27/12/2008, 13h07

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