【问题标题】:Bad Request: XML cannot be parsed 400 error Curl PHP错误请求:无法解析 XML 400 错误 Curl PHP
【发布时间】:2020-09-05 08:20:50
【问题描述】:

我正在使用 PHP POST Curl 请求来传递 XLM 数据,但我收到错误响应:

错误请求:无法解析 XML。检查您要发送到的 XML 确保它可以被解析。

$url = 'https://provapi.advancedmd.com/processrequest/API-100/DOKTORCONNECT/xmlrpc/processrequest.aspx';

$xmldata = '<ppmdmsg action="addpatient" class="demographics" msgtime="3/20/2018 2:52:07 PM"><patientlist><patient respparty="SELF" name="smith,BOB" sex="M" genderidentity="" genderidentityother="" orientation="" orientationother="" hipaarelationship="18" relationship="1" dob="03/11/1952"ssn="444-44-4444" additionalmrn="" chart="AUTO" profile="prof18" finclass="fclass16" language="44" inactivestatus="" title="MR" maritalstatus="1" employer=""><address zip="15136" city="MC KEES ROCKS" state="PA" address1="" address2="123 Main Street"/><contactinfo homephone="" officephone="" officeext="" otherphone="" othertype="" preferredcommunicationfid="" confidentialcommunicationfid="" communicationnote="" email="" emailverificationstatus="0"/></patient></patientlist><resppartylist><respparty name="SELF" accttype="4"/></resppartylist></ppmdmsg>';

$headers = array();
$headers[] = 'Content-Type: text/xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmldata);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
//Send the request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$response = curl_exec($ch);
curl_close($ch);
$array_data = json_decode(json_encode(simplexml_load_string($response)), true);
print_r('<pre>');
print_r($array_data);
print_r('</pre>');

回复如下:

Array
(
    [Results] => Array
        (
        )

    [Error] => Array
        (
            [Fault] => Array
                (
                    [faultcode] => Client
                    [faultstring] => Client Error
                    [detail] => Array
                        (
                            [code] => 400
                            [description] => Bad Request: XML cannot be parsed
                            [extrainfo] => Bad Request: XML cannot be parsed. Check the XML you are sending to make sure it can be parsed.
                        )

                )

        )

)

【问题讨论】:

    标签: php xml curl xml-parsing bad-request


    【解决方案1】:

    您调用的 API 似乎有问题!尝试像这样分配您的变量:

    $xmldata = <<<XML
    <ppmdmsg action="addpatient" class="demographics" msgtime="3/20/2018 2:52:07 PM">
        <patientlist>
            <patient respparty="SELF" name="smith,BOB" sex="M" genderidentity="" genderidentityother="" orientation=""
                     orientationother="" hipaarelationship="18" relationship="1" dob="03/11/1952" ssn="444-44-4444"
                     additionalmrn="" chart="AUTO" profile="prof18" finclass="fclass16" language="44" inactivestatus=""
                     title="MR" maritalstatus="1" employer="">
                <address zip="15136" city="MC KEES ROCKS" state="PA" address1="" address2="123 Main Street"/>
                <contactinfo homephone="" officephone="" officeext="" otherphone="" othertype=""
                             preferredcommunicationfid="" confidentialcommunicationfid="" communicationnote="" email=""
                             emailverificationstatus="0"/>
            </patient>
        </patientlist>
        <resppartylist>
            <respparty name="SELF" accttype="4"/>
        </resppartylist>
    </ppmdmsg>
    XML;
    

    【讨论】:

      猜你喜欢
      • 2017-03-04
      • 2021-05-12
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多