Catch CXML-Urlencoded with PHP. Not POST or GET

為{幸葍}努か 提交于 2019-12-25 01:12:08

问题


Is there other ways to receive a form other than POST, GET, COOKIE, SESSION and RAW?

I explain: I'm trying to implement cXML Punchout with PHP but it seems that I'm not receiveing the information as is usually sent. I try to catch it with PHP, GET, POST and even as raw:

file_get_contents('php://input')

But I don't catch any var.

I found a URL to send a dummy request to my program: https://punchoutcommerce.com/tools/cxml-punchout-tester

If I send a request my program (https://serlimax.com/api) it does not register anything in my logs, but I see there were a CXML-Urlencoded sent using browser tools.

How do I catch that that info I see?

pS: If you want to see it by yourself in the browser you can send any info but an existing URL, otherwise it'll send a 404 error.

PS2: If you're wondering how do I know I'm not receiving anything, this is how I log the received info:

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());

Resulting in an empty log:


回答1:


The problem is that you "log" your posted data incorrect. You use:

file_get_contents('php://input');

However, this returns the data. As you do not echo it, it will not be visible in your log file.

Change it to something like this:

echo file_get_contents('php://input');

After Changing that you will see your XML which you need:

<?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>



回答2:


Well it was out of my knowledge but it was due to be using https://url/api/, instead of https://url/api/index.php

The laking of "index.php" caused a redirection which avoid the catching of php://input



来源:https://stackoverflow.com/questions/59337685/catch-cxml-urlencoded-with-php-not-post-or-get

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!