提出SOAP请求时cURL返回bool(false)

时间:2019-03-08 14:58:08

标签: php curl soap

我正在尝试使用cURL发出SOAP请求,但是出现以下错误。对于结果的输出,我得到“ bool(false)”。对于curl_error()函数,我得到“ 操作在30000毫秒后超时,收到0个字节”。

我的问题是,是否可能在cURL选项中缺少某些可能阻止连接的内容?

这是我的代码:

<?php
function soap_subscriber($subscriber_email) {

    $soap_endpoint = '[HIDDEN]';
    $soap_username = '[HIDDEN]';
    $soap_userpass = '[HIDDEN]';

    define('USERNAME', '[HIDDEN]');
    define('PASSWORD', '[HIDDEN]');
    define('ENDPOINT', $soap_endpoint);
    date_default_timezone_set('America/Nassau');

    $ch = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                        xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
                        xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <soap:Header>
                            <wsse:Security soap:mustUnderstand="1">
                                <wsse:UsernameToken wsu:Id="SecurityToken-884da619-59bb-4db6-834d-138322342442">
                                    <wsse:Username> . soap_username . </wsse:Username>
                                    <wsse:Password
                                        Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"
                                        > . soap_userpass . </wsse:Password>
                                </wsse:UsernameToken>
                            </wsse:Security>
                        </soap:Header>
                        <soap:Body>
                            <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
                                <RetrieveRequest>
                                    <ClientIDs>
                                        <ID>[HIDDEN]</ID>
                                    </ClientIDs>
                                    <ObjectType>DataExtensionObject[HIDDEN]</ObjectType>
                                    <Properties>SubscriberID</Properties>
                                    <Properties>FirstName</Properties>
                                    <Properties>Email</Properties>
                                          <Filter xmlns:q1="http://exacttarget.com/wsdl/partnerAPI" xsi:type="q1:SimpleFilterPart">
                                           <q1:Property>Email</q1:Property>
                                           <q1:SimpleOperator>equals</q1:SimpleOperator>
                                           <q1:Value> . $subscriber_email . </q1:Value>
                                        </Filter>
                                </RetrieveRequest>
                            </RetrieveRequestMsg>
                        </soap:Body>
                    </soap:Envelope>';

        $soap_header = array(
            "Content-type: application/soap+xml;charset=\"utf-8\"",
            "Accept: text/xml",
            "Cache-Control: no-cache",
            "Pragma: no-cache",
            "SOAPAction: ",
            "Content-length: ".strlen($ch),
        );

        $ch = curl_init();
        $curl_options = array(
            CURLOPT_URL => ENDPOINT,
            CURLOPT_CONNECTTIMEOUT => 10,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_USERPWD => USERNAME . ':' . PASSWORD,
            CURLOPT_HTTPAUTH => CURLAUTH_ANY,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_HEADER => true,
            CURLOPT_POSTFIELDS => $ch,
            CURLOPT_HTTPHEADER => $soap_header,
            CURLOPT_POST => true,
        );

        curl_setopt_array($ch, $curl_options);

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

        curl_close($ch);

   var_dump($response);
   var_dump($error);

}

soap_subscriber('[HIDDEN]');

?>

1 个答案:

答案 0 :(得分:0)

您的SOAP请求需要30秒钟以上才能完成其执行。您可以尝试一些解决方案:

  • 增加cURL操作时间限制:

    curl_setopt($ch, CURLOPT_TIMEOUT, 400); // 400 seconds

  • set_time_limit设置为0,以使您的请求运行无限秒:

    set_time_limit(0);

    但是缺点是挂起或耗尽内存是可能的。

  • 尝试将其添加到您的cURL选项中,以防止从服务器进行无限重定向:

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

希望这会有所帮助!