【问题标题】:cURL error 58 while trying to access soap webserver尝试访问肥皂网络服务器时出现 cURL 错误 58
【发布时间】:2018-02-14 18:21:45
【问题描述】:

我正在尝试通过 https 调用(通过 PHP 脚本)远程 (SOAP) 网络服务器,它需要受密码保护的证书。 我正在使用 nuSoap 拨打电话,但我总是收到以下错误

nusoap_client:得到 wsdl 错误:获取 https://ws-t.pitre.tn.it/wcfrouting/wsdl/Documents.wsdl - HTTP 错误:cURL 错误:58:无法使用客户端证书(未找到密钥或密码错误?)

require_once("../nusoap/lib/nusoap.php");

$pitre_wsdl = "https://ws-t.pitre.tn.it/wcfrouting/wsdl/Documents.wsdl";
$client = new nusoap_client($pitre_wsdl, "wsdl");
$err = $client->getError();

if ($err) {
    print("Error");
    exit();
}

$client->setCredentials(
    "",
    "",
    "certificate",
    array (
        "sslcertfile"   =>  "../pitre/cert.p12",
        "sslkeyfile"    =>  "../pitre/cert.p12",
        "certpassword"  =>  "mypass",
        "verifypeer"    =>  FALSE,
        "verifyhost"    =>  FALSE
    )
);

$result = $client->call(
    "GetTemplatesDocuments",
    array (
        "CodeAdm"   =>  "myCode"
    )
);

使用浏览器,我可以毫无问题地访问 wisdl。我尝试了以下答案:

cURL with SSL certificates fails: error 58 unable to set private key file

我得到了同样的结果。

我错过了什么吗?

【问题讨论】:

    标签: php ssl curl certificate nusoap


    【解决方案1】:

    我找到了答案,我的解决方法如下:

    我无法使其与 nu_soap 一起使用,因此我切换到 SoapClient

    首先我必须使用 openssl 将我的 p12 证书转换为 pem 格式

    openssl pkcs12 -in certificato.p12 -out certificato.pem -clcerts
    

    然后我从https://curl.haxx.se/docs/caextract.html这里下载了CA证书

    这是我的工作代码

    $params->a              = "a";
    $params->b               = "b";
    $params->c               = "c";
    $params->d               = "d";
    $params->e               = "e"; 
    
    $context = stream_context_create(array (
        "ssl"   =>  array (
            "verify_peer"       =>  false,
            "verify_peer_name"  =>  true,
            "local_cert"        =>  getcwd()."\certificato.pem",  //complete path is mandatory
            "passphrase"        =>  "mypassphrase",
            "allow_self_signed" =>  true
        ),
        "https" =>  array (
            "curl_verify_ssl_peer"  =>  false,
            "curl_verify_ssl_host"  => false
        )
    ));
    
    $pitre_client = new SoapClient($pitre_wsdl, array (
        "trace"             =>  1,
        "exceptions"        =>  true,
        "location"          =>  "https://ws-t.pitre.tn.it/wcfrouting/servicerouter.svc",
        "cafile"            =>  getcwd()."\cacert.pem", //complete path is mandatory
        "stream_context"    =>  $context
    ));
    
    // the call
    $response = $pitre_client->GetTemplatesDocuments(
        array (
            'request' => $params  //request key can be different
        )
    );
    

    希望对遇到同样问题的人有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 2017-01-16
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多