第三者のWebサービスを使用したいと思います。 Webサービスを使用するには、HTTPSに接続する必要があります。私の問題は、開発プロセスでは、私は無効な証明書を持つテストAPIを持っているということです。 SoapClient noにサーバーの証明書を確認するように設定したいと思います。ここで私が試した方法です:Php SoapClient stream_contextオプション
$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
));
私もCURLで試してみました!しかし、私はSoapClientを使いたいです。あなたは以下のCURLを使用してコードを見つけることができます。
// 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);
あなたは、私はそれを投稿してくださいのSoapClientを使用して提供されているコードにバグを発見した場合。おかげさまで
正確なエラーは何ですか? – Baba
これは、PHPエラーログのエラーメッセージです。 [28-Mar-2012 18:00:54] PHP警告:SoapClient :: SoapClient()[soapclient.soapclient]:SSL操作がコード1で失敗しました:OpenSSLエラーメッセージ: エラー:14094410:SSLルーチン:SSL3_READ_BYTES:行51のC:\ wamp \ www \ FDGGwsTest \ test.phpのsslv3アラートハンドシェイクエラー –
リモートホストは特定のIPアドレスからの接続が必要ですか? – Baba