doujing6436 2018-10-03 11:27
浏览 76

通过php发送带有.PFX文件的Soap Request

I try to do SOAP request with .pfx file and i got error like:

SOAP-ERROR: Parsing WSDL: Couldn't load from : failed to load external entity

my code look like that :

    $this->api_url = "https://wsa.clalbit.co.il/CalcCampaignPremia.asmx?WSDL";

    $certificate   = dirname( __FILE__ ) . '/ws-hova.pfx';
    $options       = array(
        'cache_wsdl' => WSDL_CACHE_NONE,
        'trace'          => 1,
        'local_cert'     => $certificate,
        'stream_context' => stream_context_create( array(
            'ssl' => array(
                'verify_peer'       => false,
                'verify_peer_name'  => false,
                'allow_self_signed' => true
            )
        ) )
    );

    try {
        $this->soap = new SoapClient( $this->api_url, $options );
    } catch (SoapFault $e) {
        echo $e->getMessage();
    }

can't understand why it is not working.

thank's for any advice

  • 写回答

1条回答 默认 最新

  • dousuiguang9328 2018-10-06 09:46
    关注

    The native PHP soap client class can not work with pfx certificates. You have to turn your pfx file into a pem file. For this purpose install the openssl toolkit and run the following command in your shell / command line interface.

    openssl pkcs12 -in ws-hova.pfx -out ws-hova.pem -nodes -clcerts
    

    After you 've done creating a pem certificate out of your pfx certificate you can simply use it with the PHP soap client.

    $certificate = dirname( __FILE__ ) . '/ws-hova.pem';
    $options = [
        'cache_wsdl' => WSDL_CACHE_NONE,
        'exceptions' => true,
        'trace' => true,
        'local_cert' => $certificate,
        'authentication' => SOAP_ATHENTICATION_DIGEST,
    ];
    
    try {
        $client = new SoapClient( $this->api_url, $options );
    } catch (SoapFault $e) {
        echo $e->getMessage();
    }
    

    This will do the trick. ;) Have fun.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line