简体   繁体   English

带有POST和PHP的XML的REST API是否应该返回false?

[英]REST API with POST and XML in PHP returns false when it shouldn't?

So the makers of this API has my code clearly marked as functional, seeing as they made the damn thing. 因此,此API的创建者将我的代码清楚地标记为可以正常运行,因为他们做了该死的事情。 The thing is, that the REST API works fine as long as I use PI or QS alone. 事实是,只要我单独使用PI或QS,REST API就可以正常工作。 When I try to use the more advanced features requiring an XML document being sent with the REST request, it just returns false on the execution. 当我尝试使用更高级的功能要求将XML文档与REST请求一起发送时,它只会在执行时返回false。

<?php

$objCurlToken = curl_init();
$strUrlToken = "https://servername/apimember/services/rest/connect/open/username/password/token";
$arrCurlOptions1 = array(
    CURLOPT_URL => $strUrlToken,
    CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($objCurlToken, $arrCurlOptions1);
$strXMLToken = curl_exec($objCurlToken);
$objXML = simplexml_load_string($strXMLToken);
curl_close($objCurlToken);


$strXMLPost = '
<?xml version="1.0" encoding="utf-8"?>
<synchroMember>
    <memberUID>
        EMAIL
    </memberUID>
    <dynContent>
        <entry>
            <key>
                EMAIL
            </key>
            <value>
                klaus@lagerbrau.de
            </value>
        </entry>
        <entry>
            <key>
                FIRSTNAME
            </key>
            <value>
                KLAUS LAGER
            </value>
        </entry>
        <entry>
            <key>
                EMVADMIN1
            </key>
            <value>
                This is klaus lager, the test subject
            </value>
        </entry>
    </dynContent>
</synchroMember>
';
$objCurlProbe = curl_init();
$strUrlProbe = "https://servername/apimember/services/rest/member/insertOrUpdateMember/" . $objXML->result . "";
$arrCurlOptions2 = array(
    CURLOPT_URL => $strUrlProbe,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $strXMLPost
);
curl_setopt_array($objCurlProbe, $arrCurlOptions2);
$strCurlXMLResult = curl_exec($objCurlProbe);
echo "<pre>";
var_dump(htmlentities($objXML->result));
var_dump(htmlentities($strXMLPost));
var_dump(htmlentities($strCurlXMLResult));
curl_close($objCurlProbe);
$objXMLResult = simplexml_load_string($strCurlXMLResult);
var_dump($objXMLResult);
?>

The output looks as follows: 输出如下:

string(84) "*tokenkey*"
string(615) "
<?xml version="1.0" encoding="utf-8"?>
<synchroMember>
    <memberUID>
        EMAIL
    </memberUID>
    <dynContent>
        <entry>
            <key>
                EMAIL
            </key>
            <value>
                klaus@lagerbrau.de
            </value>
        </entry>
        <entry>
            <key>
                FIRSTNAME
            </key>
            <value>
                KLAUS LAGER
            </value>
        </entry>
        <entry>
            <key>
                EMVADMIN1
            </key>
            <value>
                This is klaus lager, the test subject
            </value>
        </entry>
    </dynContent>
</synchroMember>
"
string(0) ""
bool(false)

Taken from API documentation: 取自API文档:

***Insert or Update Member Data***
This method searches a specified column of the Member table for a particular value used to identify a member
in order to update the member's data. If the member is not found, a new member is created. Any criteria can
be used to find the member including one of the fields to be updated.
The memberUID attribute is used to specify the key and value used as search criteria. The dynContent attribute
should only contain the values to be updated.
**insertOrUpdateMember**
***Input***
https://{server}/apimember/services/rest/member/insertOrUpdateMember/{token}
<?xml version="1.0" encoding="utf-8"?>
<synchroMember>
<memberUID>
{fieldNameA},
{fieldNameB}
</memberUID>
<dynContent>
<entry>
<key>>
{fieldNameA}
</key>
<value>
{fieldValueA}
</value>
</entry>
<entry>
<key>
{fieldNameB}
</key>
<value>
{fieldValueB}
</value>
</entry>
<entry>
<key>
{fieldNameC}
</key>
<value>
{fieldValueC}
</value>
</entry>
</dynContent>
</synchroMember>

I found the problem, the problem was in missing header describing the document as XML. 我发现了问题,问题在于缺少将文档描述为XML的标头。 As far as I know this shouldn't be a problem on normal REST servers, seeing as the only accepted data form is XML. 据我所知,在普通的REST服务器上这应该不是问题,因为唯一接受的数据格式是XML。 What didn't help the matter is that the company is pretty horrible at software development, so the system never responds with errors and if it does, they are not human readable, and the company does not supply an error code list. 对此无济于事的是,该公司在软件开发方面相当恐怖,因此该系统永远不会响应错误,并且如果出现错误,则无法人工读取,并且该公司也不会提供错误代码列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM