代码之家  ›  专栏  ›  技术社区  ›  Stefano Pernat

尝试访问soap Web服务器时出现cURL错误58

  •  1
  • Stefano Pernat  · 技术社区  · 8 年前

    我正在使用 努索普 但我总是会遇到以下错误

    nusoap_客户端:获取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"
        )
    );
    

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

    我得到了同样的结果。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Stefano Pernat    8 年前

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

    我没能让它工作 nu_肥皂 SoapClient

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

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

    这是我的工作代码

    $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
        )
    );