在curl响应中拆分头数组

时间:2015-02-04 00:25:54

标签: php

$headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "SOAPAction: http://ctitechnology.com/UpsertEntity",
                    "Content-length: ".strlen($soap_request),
                );


$soap_do = curl_init();
        curl_setopt($soap_do, CURLOPT_URL, "http://66.7.227.4/tio_ws/ScreeningPartnerWS.asmx");
        curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($soap_do, CURLOPT_POST, true);
        curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request); // the SOAP request
        curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($soap_do, CURLOPT_HEADER, true);
        curl_setopt($soap_do, CURLINFO_HEADER_OUT, true);

        $result = curl_exec($soap_do);


    print "Response:\n";
    print($result);
    print "\n";

    if($result === false) {
            $error = 'Curl error: ' . curl_error($soap_do);
            curl_close($soap_do);
            print $error;
    } else {

            $xml = simplexml_load_string($result);
            print_r($xml);
            print "\n";

我试图在响应中返回时分割标题(我需要保留标题,将CURLOPT_HEADER变为false会这样做但我需要保持响应的标题完好无损)。目前,我无法解析xml,因为包含了标头。任何智慧都将不胜感激!

1 个答案:

答案 0 :(得分:1)