Disable certificate verification in PHP SoapClient

前端 未结 4 2145
遇见更好的自我
遇见更好的自我 2020-11-27 03:06

Summary:
Is there a way to force the built in SoapClient-class in PHP to connect over HTTPS to a server with an invalid certificate?

Wh

4条回答
  •  感情败类
    2020-11-27 04:01

    SoapClient takes a stream context in its parameters, which you can create yourself. That way you can control almost every aspect of the transport layer:

    $context = stream_context_create([
        'ssl' => [
            // set some SSL/TLS specific options
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        ]
    ]);
    
    $client  = new SoapClient(null, [
        'location' => 'https://...',
        'uri' => '...', 
        'stream_context' => $context
    ]);
    

    Documentation:

    • stream_context_create() Docs
    • HTTP context options Docs
    • SSL context options Docs

提交回复
热议问题