简体   繁体   English

使用 cURL 和 Laravel 登录soap API

[英]Logging into a soap API with cURL and Laravel

I'm having some trouble with this.我在这方面遇到了一些麻烦。 I am trying to login to a Soap API with SSL I have generated the .pem file and can verify it is good by doing the following我正在尝试使用 SSL 登录 Soap API 我已经生成了 .pem 文件并且可以通过执行以下操作来验证它是否正常

curl -v --cert mycertfile.pem --pass mypassword https://someurl.com:9443/login/

The following give me HTTP/1.1 202 Accepted下面给我HTTP/1.1 202 Accepted

Now, when I essentially try to do the same thing within a laravel controller with the following, I get the following error "curl error: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate"现在,当我基本上尝试使用以下内容在 laravel 控制器中执行相同的操作时,出现以下错误“curl 错误:错误:14094412:SSL 例程:ssl3_read_bytes:sslv3 警报错误证书”

Here is the code in my controller这是我的控制器中的代码

$apiKey = 'mypassword';
$file = File::get(storage_path('app/certs/mycertfile.pem'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://someurl:9443/login/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('AUTH-KEY: ' . $apiKey));
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, 'mypassword');
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLKEY, $file);
$rawBody = curl_exec($ch);
if($rawBody === false)
{
  $err = 'curl error: ' . curl_error($ch);
  curl_close($ch);
  echo $err;
  return $err;
}
else
{
  echo "response ==";
  echo $rawBody;
  echo "execu";
  curl_close($ch);
  return 'Operation completed without any errors';
}

Any ideas why using curl from the command line using the same key, same computer, URL and .pem file is OK, where as using cURL in laravel, gives this error?任何想法为什么使用相同的密钥、相同的计算机、URL 和 .pem 文件从命令行使用 curl 是可以的,而在 laravel 中使用 cURL 会出现此错误? Interestingly, I am sure this used to work, but have since upgraded to PHP8 and a few other things I think.有趣的是,我确信这曾经有效,但后来升级到 PHP8 和我认为的其他一些东西。 Perhaps that is why, but I can't see anything mentioning issues with PHP8.也许这就是原因,但我看不到任何提及 PHP8 问题的内容。

After a bit of research, I was able to get the above working by using the following.经过一番研究,我能够通过使用以下内容来完成上述工作。

$client = new \SoapClient('location of wsdl file.wsdl', array(
                    'local_cert' => 'mycertfile.pem',
                    'passphrase' => 'mypassword',
                    // 'location' => 'https://webserviceurl/login/' 
                )
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM