duanqian8867 2019-03-08 14:58
浏览 205

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

I am trying to make a SOAP request using cURL but I am getting the following errors. For the output of the result, I get "bool(false)". For the curl_error() function, I get "Operation timed out after 30000 milliseconds with 0 bytes received".

My question is whether I am missing something that could be preventing the connection, possibly in the cURL options?

This is my code:

<?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条回答 默认 最新

  • dongwei3151 2019-03-08 15:18
    关注

    Your SOAP request requires more than 30 seconds to finish its execution. Some solutions you can try:

    • Increase cURL operation time limit:

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

    • Set set_time_limit to 0 to make your requests run for infinite seconds:

      set_time_limit(0);

      but downside is that hanging or running out of memory is possible.

    • Try adding this to your cURL options to prevent infinite redirection from the server:

      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

    Hope this helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程