2

I'm trying to make a soap request with HTTPS link. I get Curl Failed: 0 (that means no error) However, I received a empty string.

$url = $soapUrl;

$soap_do = curl_init();
set_time_limit(0);
curl_setopt($soap_do, CURLOPT_URL,            $url);
curl_setopt($soap_do, CURLOPT_AUTOREFERER,    true);
curl_setopt($soap_do, CURLOPT_MAXREDIRS,      10);
curl_setopt($soap_do, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($soap_do, CURLOPT_POST,           true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $xml_post_string);
curl_setopt($soap_do, CURLOPT_VERBOSE,        TRUE);
curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $headers);

$response = curl_exec($soap_do);
$error    = curl_error($soap_do);

var_dump($response);

echo "Curl Failed: " . curl_errno($soap_do), "<br/>";
echo curl_error($soap_do);

Any problem with my code?

1 Answers1

0

Where is your curl_exec();?

You are setting a ton of options, but I think the most ones are just for finetuning. You could try it with this example I gave in another answer:

Send an XML post request to a web server with CURL

EDIT: PHP also has a SOAP Client build in, maybe you could give it a try:

    $context = stream_context_create([
        'http' => [
            'user_agent' => 'PHPSoapClient'
        ],
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        ]
    ]);

    $soap = new SoapClient($url, [
        'stream_context' => $context,
        'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
        'trace' => 1,
        'exception' => 1,
        'keep_alive' => false,
        'connection_timeout' => 500000
    ]);

    // Then call the SOAP method
    echo $soap->version();
Community
  • 1
  • 1
PKeidel
  • 2,559
  • 1
  • 21
  • 29
  • Your updated code works fine for me. Maybe you should set `CURLOPT_SSL_VERIFYPEER false` or try the build in SoapClient. See my updated answer – PKeidel May 08 '17 at 15:24
  • Do I need to have a certificates for me to access the https link? –  May 08 '17 at 15:26
  • I tried you updated code but it refuse, see the error `Fatal error: Class 'SoapClient' not found` –  May 08 '17 at 15:31
  • For SSL you need to set `verify_peer => true` and `allow_self_signed => false` – PKeidel May 08 '17 at 15:36
  • SoapClient needs the php soap extension installed. On a debian based system this is as simple as "apt install php7.0-soap" – PKeidel May 08 '17 at 15:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143704/discussion-between-phpmeter-and-pkeidel). –  May 08 '17 at 15:39