使用 PHP 捕获 CXML-Urlencoded。不是 POST 或 GET
Catch CXML-Urlencoded with PHP. Not POST or GET
除了 POST、GET、COOKIE、SESSION 和 RAW 之外,还有其他方法可以接收表单吗?
我解释一下:我正在尝试使用 PHP 实现 cXML Punchout,但似乎我没有收到通常发送的信息。我尝试用 PHP、GET、POST 甚至 raw:
来捕捉它
file_get_contents('php://input')
但我没有捕捉到任何变种。
我找到了一个 URL 来向我的程序发送一个虚拟请求:https://punchoutcommerce.com/tools/cxml-punchout-tester
如果我向我的程序 (https://serlimax.com/api) 发送请求,它不会在我的日志中注册任何内容,但我看到有一个使用浏览器工具发送的 CXML-Urlencoded。
如何捕捉我看到的信息?
pS:如果您想在浏览器中自己查看,您可以发送除现有 URL 之外的任何信息,否则会发送 404 错误。
PS2:如果您想知道我怎么知道我没有收到任何东西,这就是我记录收到的信息的方式:
ob_flush();
ob_start();
echo "User: - ". $_SERVER['HTTP_USER_AGENT']. ' - IP:'. $_SERVER['REMOTE_ADDR'].' - METHOD:'.$_SERVER['REQUEST_METHOD'].PHP_EOL;
echo 'POST:---------'.PHP_EOL;
var_dump($_POST);
echo 'GET:---------'.PHP_EOL;
var_dump($_GET);
echo 'RAW:---------'.PHP_EOL;
echo file_get_contents('php://input');
file_put_contents('./punchout_log_'.date("j.n.Y.H.i.s").'.txt', ob_get_flush());
导致空日志:
问题是您 "log" 您发布的数据不正确。您使用:
file_get_contents('php://input');
不过,这个returns数据。由于您不回显它,因此它不会出现在您的日志文件中。
改成这样:
echo file_get_contents('php://input');
更改后您将看到您需要的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.041/cXML.dtd">
<cXML payloadID="1576588580.7783@punchoutcommerce.com" timestamp="2019-12-17T13:16:20+00:00">
<Header>
<From>
<Credential domain="NetworkId">
<Identity>test</Identity>
</Credential>
</From>
<To>
<Credential domain="DUNS">
<Identity>tww</Identity>
</Credential>
</To>
<Sender>
<Credential domain="NetworkId">
<Identity>ewe</Identity>
<SharedSecret>wew</SharedSecret>
</Credential>
<UserAgent>PunchOutCommerce PunchOut Tester</UserAgent>
</Sender>
</Header>
<Request deploymentMode="production">
<PunchOutSetupRequest operation="create">
<BuyerCookie>76930ae895ac62a2a7e0c9d9350fa5f2</BuyerCookie>
<Extrinsic name="User">jdoe12345</Extrinsic>
<Extrinsic name="UniqueUsername">jdoe12345</Extrinsic>
<Extrinsic name="UserId">12345</Extrinsic>
<Extrinsic name="UserEmail">jdoe@example.com</Extrinsic>
<Extrinsic name="UserFullName">John Doe</Extrinsic>
<Extrinsic name="UserPrintableName">John Doe</Extrinsic>
<Extrinsic name="FirstName">John</Extrinsic>
<Extrinsic name="LastName">Doe</Extrinsic>
<Extrinsic name="PhoneNumber">555-555-5555</Extrinsic>
<BrowserFormPost>
<URL>https://punchoutcommerce.com/tools/cxml-punchout-return</URL>
</BrowserFormPost>
<SupplierSetup>
<URL>http://52.211.159.83/test.php?test=1</URL>
</SupplierSetup>
<ShipTo>
<Address addressID="TEST">
<Name xml:lang="en">TEST</Name>
<PostalAddress>
<Street>123 Street Address</Street>
<City>Rockville</City>
<State>MD</State>
<PostalCode>20850</PostalCode>
<Country isoCountryCode="US">US</Country>
</PostalAddress>
</Address>
</ShipTo>
</PunchOutSetupRequest>
</Request>
</cXML>
嗯,这超出了我的知识,但它应该使用 https://url/api/, instead of https://url/api/index.php
缺少 "index.php" 导致重定向,避免捕获 php://input
除了 POST、GET、COOKIE、SESSION 和 RAW 之外,还有其他方法可以接收表单吗?
我解释一下:我正在尝试使用 PHP 实现 cXML Punchout,但似乎我没有收到通常发送的信息。我尝试用 PHP、GET、POST 甚至 raw:
来捕捉它file_get_contents('php://input')
但我没有捕捉到任何变种。
我找到了一个 URL 来向我的程序发送一个虚拟请求:https://punchoutcommerce.com/tools/cxml-punchout-tester
如果我向我的程序 (https://serlimax.com/api) 发送请求,它不会在我的日志中注册任何内容,但我看到有一个使用浏览器工具发送的 CXML-Urlencoded。
如何捕捉我看到的信息?
pS:如果您想在浏览器中自己查看,您可以发送除现有 URL 之外的任何信息,否则会发送 404 错误。
PS2:如果您想知道我怎么知道我没有收到任何东西,这就是我记录收到的信息的方式:
ob_flush();
ob_start();
echo "User: - ". $_SERVER['HTTP_USER_AGENT']. ' - IP:'. $_SERVER['REMOTE_ADDR'].' - METHOD:'.$_SERVER['REQUEST_METHOD'].PHP_EOL;
echo 'POST:---------'.PHP_EOL;
var_dump($_POST);
echo 'GET:---------'.PHP_EOL;
var_dump($_GET);
echo 'RAW:---------'.PHP_EOL;
echo file_get_contents('php://input');
file_put_contents('./punchout_log_'.date("j.n.Y.H.i.s").'.txt', ob_get_flush());
导致空日志:
问题是您 "log" 您发布的数据不正确。您使用:
file_get_contents('php://input');
不过,这个returns数据。由于您不回显它,因此它不会出现在您的日志文件中。
改成这样:
echo file_get_contents('php://input');
更改后您将看到您需要的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.041/cXML.dtd">
<cXML payloadID="1576588580.7783@punchoutcommerce.com" timestamp="2019-12-17T13:16:20+00:00">
<Header>
<From>
<Credential domain="NetworkId">
<Identity>test</Identity>
</Credential>
</From>
<To>
<Credential domain="DUNS">
<Identity>tww</Identity>
</Credential>
</To>
<Sender>
<Credential domain="NetworkId">
<Identity>ewe</Identity>
<SharedSecret>wew</SharedSecret>
</Credential>
<UserAgent>PunchOutCommerce PunchOut Tester</UserAgent>
</Sender>
</Header>
<Request deploymentMode="production">
<PunchOutSetupRequest operation="create">
<BuyerCookie>76930ae895ac62a2a7e0c9d9350fa5f2</BuyerCookie>
<Extrinsic name="User">jdoe12345</Extrinsic>
<Extrinsic name="UniqueUsername">jdoe12345</Extrinsic>
<Extrinsic name="UserId">12345</Extrinsic>
<Extrinsic name="UserEmail">jdoe@example.com</Extrinsic>
<Extrinsic name="UserFullName">John Doe</Extrinsic>
<Extrinsic name="UserPrintableName">John Doe</Extrinsic>
<Extrinsic name="FirstName">John</Extrinsic>
<Extrinsic name="LastName">Doe</Extrinsic>
<Extrinsic name="PhoneNumber">555-555-5555</Extrinsic>
<BrowserFormPost>
<URL>https://punchoutcommerce.com/tools/cxml-punchout-return</URL>
</BrowserFormPost>
<SupplierSetup>
<URL>http://52.211.159.83/test.php?test=1</URL>
</SupplierSetup>
<ShipTo>
<Address addressID="TEST">
<Name xml:lang="en">TEST</Name>
<PostalAddress>
<Street>123 Street Address</Street>
<City>Rockville</City>
<State>MD</State>
<PostalCode>20850</PostalCode>
<Country isoCountryCode="US">US</Country>
</PostalAddress>
</Address>
</ShipTo>
</PunchOutSetupRequest>
</Request>
</cXML>
嗯,这超出了我的知识,但它应该使用 https://url/api/, instead of https://url/api/index.php
缺少 "index.php" 导致重定向,避免捕获 php://input