Ich möchte den Web-Service eines Drittanbieters verwenden. Um den Web-Service nutzen zu können, muss ich mich mit HTTPS verbinden. Mein Problem ist, dass ich für den Entwicklungsprozess eine Test-API mit einem ungültigen Zertifikat habe. Ich möchte SoapClient auf Nein setzen, um das Zertifikat des Servers zu überprüfen. Hier ist die Art, wie ich es versuchte:PHP SoapClient stream_context Option
$opts = array(
'ssl' => array(
'verify_peer' => false
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false
)
);
$streamContext = stream_context_create($opts);
$client = new SoapClient("https://urlToSoapWs",
array(
'login' => 'user',
'password' => 'pwd',
'authentication' => SOAP_AUTHENTICATION_BASIC,
'local_cert' => file_get_contents('C:/somelocation/1.pem'),
'passphrase' => 'passphrase',
'stream_context' => $streamContext
));
Ich habe auch versucht mit CURL und arbeitete! Aber ich möchte SoapClient verwenden. Sie können den Code mit curl unten finden:
// create a new cURL resource
$ch = curl_init("https://urlToSoapWs");
// setting the request type to POST:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
// setting the authorization method to BASIC:
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// supplying your credentials:
curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
$body = "<SOAP-ENV:Envelope>somexmlhere</SOAP-ENV:Envelope>";
// filling the request body with your SOAP message:
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// configuring cURL not to verify the server certificate:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSLCERT, "pathToTheCertificatePemFile");
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "pwd");
//curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");
curl_setopt($ch, CURLOPT_SSLKEY, "pathTotheKeyFile");
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "pwd");
// telling cURL to return the HTTP response body as operation result
// value when calling curl_exec:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// calling cURL and saving the SOAP response message in a variable which
// contains a string like "<SOAP-ENV:Envelope ...>...</SOAP-ENV:Envelope>":
$result = curl_exec($ch);
// closing cURL:
curl_close($ch);
Wenn Sie den Fehler im Code gefunden haben, die ich mit dem Soapclient zur Verfügung gestellt bitte posten. Danke.
was ist der genaue Fehler, den Sie haben ?? – Baba
Dies ist die Fehlermeldung aus PHP-Fehlerprotokoll: [28-Mar-2012 18:00:54] PHP Warnung: SoapClient :: SoapClient() [soapclient.soapclient]: SSL-Vorgang mit Code fehlgeschlagen 1. OpenSSL-Fehlermeldungen: Fehler : 14094410: SSL-Routinen: SSL3_READ_BYTES: sslv3-Alert-Handshake-Fehler in C: \ wamp \ www \ FDGGwsTest \ test.php in Zeile 51 –
Benötigt der Remote-Host eine Verbindung von einer bestimmten IP-Adresse ??? – Baba