I am sending this request from Insomnia (a PostMan like software). I am sending a simple XML file
<?xml version='1.0' encoding='UTF-8'?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
And on Header i only have Content-Type: application/xml I am sending this to an php file which contains this code:
$xml = file_get_contents('php://input');
echo "<pre>";
print_r(htmlspecialchars($xml));
echo "</pre>";
Which is outputting an empty string. On my local server it's outputting the xml file how it should be.
My settings on my paid server are:
My Insomnia screen looks like this:
The output comes from this code:
echo "<pre>";
print_r($_POST);
echo "</pre>";
Outputs the empty array and:
if (!empty($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/xml') {
echo "application/xml";
}
Outputs "application/xml".
Answer: it turns out in my case i should have wrote the address with HTTPS instead of HTTP.
Many factors can affect this:
It might happen because you are accessing incorrect site url. Eg: http://mysite and https://mysite are two different sites.
It might happen if you are sending your request as form data.
Also if allow_url_fopen
is set to Off
. To allow url fopen you just need to add a line in php.ini
: ini_set("allow_url_fopen", true);
This might even happen if you have a redirect from mysite.com
to something.mysite.com
or vice-versa. To verify any redirects, you should first check the .htaccess
. If there is no redirect using .htaccess
, then add some kind of count in super global like $_SESSION
and increment it. If the count is more than 1, then you have a redirect.
You might be able find some information in server logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With