PHP won't receieve POST XML data - php

I'm building a service backend that is being sent a "delivery report" after successfully sending a SMS to a user.
The report itself is XML POSTed to our "endpoint" with the content-type application/xml.
I'm using Postman to make sure that everything is working correctly. I've made a test using regular JSON and can return the data without issues, however, no matter what I try with XML I basically get no indication that anything is being sent to the server.
(Test with JSON)
(Test with XML)
Here's my simple PHP script:
<?php
header('Content-Type: application/xml; charset=utf-8');
print_r(json_decode(file_get_contents("php://input"), true));
print_r($HTTP_RAW_POST_DATA);
?>
I feel like I've tried everything. Been looking at past issues posted to SO and other places, it simply won't work for me. I'm hoping for some answers that at least points me in the right direction here.
Cheers.

Your trying to json_decode XML data. You should use something like SimpleXML.
Instead of...
print_r(json_decode(file_get_contents("php://input"), true));
You should use ...
$xml = new SimpleXMLElement(file_get_contents("php://input"));
echo $xml->asXML();
You should be able to get the information by (for example)...
echo (string)$xml->id;

json_decode can't read XML, seems like you're trying to parse XML with json_decode. if you want to output the received XML, use echo (or if it's for debugging purposes, use var_dump, eg var_dump(file_get_contents("php://input"));), or if you want to parse the XML, use DOMDocument.

Related

I want to send requests from a UE4 c++ game to my php script, so that it interacts with a mysql database

i'm searching the inet for around 3 days now and i'm stuck at this.
I got a MySQL Database and a php Script, as well as a Game made in UE4.
UE4 uses c++.
So now i want to send requests from the c++ game to the php script and that shall interact with the database.
For example create an account or login. I also want to pass the mysql query result of the php script to my c++ class.
I tried using HttpRequest, but i can't get data from php to c++ with that.
Maybe you can, but i don't understand it at all.
What i accomplished by now is that you can send a POST request from the game to the php script and pass variables so that the script uses them to perform the mysql query.
But how can i pass data from the php file to c++ now? The response i get is always the whole site (head and body) and i don't know where i could save the query result to pass it to the c++ code.
I'm a full beginner here, so go easy on me. I read so many different posts and blogs that my brain hurts like hell ): I hope someone can tell me how to do this easily or at least give me a hint on what i have to google and what i could use. I don't need a full tutorial, just a name of a library better than the Http.h (if simple HttpRequest cant manage this) would be enough. ): I'm really frustrated...
eXi
The PHP script should retun a HTTP response reduced to a bare minimum. It doesn't even need to be a HTML document:
<?php
// file: api.php
$param = $_POST['myparam'];
$foo = bar($param); // $foo contains e.g. "1,ab,C"
echo $foo; // if you opened http://myhost.com/api.php in a browser
// all you would see is "1,ab,C"
// (which is not a valid HTML document, but who cares)
?>
Then parse this HTTP response (a plain string, that is) from your game. You can use your own data format, or use a well-known format of your choice (XML or JSON are good candidates).
The json object in unreal is pretty good, so I would recommend outputting json from your php script. Json in php is a pretty natural workflow.
<?php
$obj['userid'] = 5476;
$obj['foo'] = 'bar';
echo json_encode($obj);
php?>
That will echo out
{"userid":5476,"foo":"bar"}
If that's all you output in your script then it's pretty straightforward to treat that as a string and populate an unreal json object with it.
FString TheStuffIGotFromTheServer;
TSharedPtr<FJsonObject> ParsedJson;
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(TheStuffIGotFromTheServer);
if (FJsonSerializer::Deserialize(JsonReader, ParsedJson))
{
FString foo = ParsedJson.GetStringField("foo");
double UserId = ParsedJson.GetNumberField("userid");
}
Check out the unreal json docs to get a feel for what you can do with it.

XML received from response is out of format

Hi im currently using PHP on a linux server to receive response from a WebService hosted on a Windows server.
I am using the following PHP to read the response :-
while (!feof($socket)) {
$result .= fgets($socket, 4096);
}
fclose($socket);
if ($debug) echo '<pre>',$result,'</pre>';
Apparently when i received the the response it is out of format, with break lines between tags such as the following :-
/9j/4AAQSkZJRgABAQEAYABgAAD/4QBaRXhpZgAATU0AKgAAAAgABQMBAAUAAAABAAAASgMDAAEAAAABAAAAAFEQAAEAAAABAQAAAFERAAQAAAABAAAAAFESAAQAAAABAAAAAAAAAAA
AAYagAACxj
insetead of like these :-
</ResponseHdr><ResGetCustAreaSnapshot><cmc:GetCustAreaSnapshot xmlns:cmc="http://tnb.com.my/CGIS/D/cmc_customermgnt"><cmc:MAP_IMAGE_ZOOM1000>/9j/4AAQSkZJRgABAQEAYABgAAD/4QBaRXhpZgAATU0AKgAAAAgABQMBAAUAAAABAAAASgMDAAEAAAABAAAAAFE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yO8sPD+lWl1HnZNBZRxuuQQcMACMgkfjWxRWRZnQf8AIy33/Xnb/wDoc1aNZ0H/ACMt9/152/8A6HNWjQAUUUUAFZXhf/kUtG/68YP/AEWtatZXhf8A5FLRv+vGD/0Wtar+FL1X5Mh/GvR/oatFFFZFmdB/yMt9/wBedv8A+hzVo1nQf8jLff8AXnb/APoc1aNABRRRQBU1S9/s3Sb2/wDL8z7NA82zdjdtUnGe3SjS7L+zdJsrDzPM+zQJDv243bVAzjtnFVfFH/Ipaz/14z/+i2rVrV6Ul5t/glb82R9v5f1+QUUUVkWFccdVlW0uLC2LRFbq4M85VvkVrhwAAPmJJ4G35mPypzuaO/q2tlbcGLi3l4iZHIkuOQPkwCVQllG8ZY5ARSzoTzls832WFFHlYRX+0YAAVh5fmKqMTvfBRduOMRwfLmUduGwzmueW35nPWrcvurcybrRli1vR2sY8RWurJcXKZB8oyPDH1X50fe8
apparently even from here i cannot display the tags without using the code block which formats it properly.
would really appreciate it if someone could point me in the right direction on what to look for to fix this problem.
Thank You.
'ow do you look at your debug output: inside a browser or inside a terminal ? Could it be that you simply have the xml like tags ("<...>") in the reply swallowed by visualizing it as html in a browser ?
If that is not the case then I would check the content of the reply on a lower level. Use 'tcpdump' or 'wireshark' to dump the actual content without having to rely on a higher level output.
Try var_dump(htmlspecialchars($result)) instead of echo.

storing an html in a variable php then echoing it

I'm storing an html in a php variable by using a $_GET method.
This is what I did.
http://myurl.com?html=%3Cdiv%20class=%22invoice-logo%22%20style=%22float:left;margin-bottom:15px;%22%3E%3Cimg%20src=%22https://myurl/account/images/invoice_logo.gif%22%20title=%22New%20Covenant%20Software%22%3E%3C/div%3E%3Cdiv%20style=%22clear:both%22%3E%3C/div%3E%3Ch3%20class=%22invoiceNum%22%20style=%22padding:0px;font-size:25px;%22%3E%3Cstrong%3EInvoice#9368%3Cstrong%3E%3C/strong%3E%3C/strong%3E%3C/h3%3E%3Ctable%20class=%22widefat%22%20style=%22font-size:12px;margin-bottom:6px;width:48%;%22%3E%3Ctbody%3E%3Ctr%3E%3Ctd%20class=%22table_heading%22%20style=%22text-align:left;%22%3EBill%20To%3C/td%3E%3Ctd%20class=%22table_heading%22%20style=%22text-align:left;%22%3EContact%20Us%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22text-align:left;background-color:white;%22%20class=%22table_body%22%3ETravis%20Harris%3Cbr%3ENew%20Covenant%20Software%3Cbr%3E322%20Old%20Mill%20Rd%3Cbr%3ENewmanstown,%20PA%2017073%3C/td%3E%3Ctd%20style=%22text-align:left;background-color:white;%22%20class=%22table_body%22%3ENew%20Covenant%20Software%3Cbr%3E%3Cb%3E%28866%29%20213-6539%3C/b%3E%3Cbr%3E%3Ca%20rel=%22noreferrer%22%20onclick=%22window.open%28%27https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=billing#newcovsoft.com%27,%27Compose%20new%20message%27,%27width=640,height=480%27%29;return%20false%22%20title=%22[GMCP]%20Compose%20a%20new%20mail%20to%20billing#newcovsoft.com%22%20href=%22mailto:billing#newcovsoft.com%22%3Ebilling#newcovsoft.com%3C/a%3E%3Cbr%3E%3C/td%3E%3C/tr%3E%3C/tbody%3E%3C/table%3E%3Cdiv%20style=%22float:right;margin-bottom:5px;%22%3E%3Cstrong%3EDate:%20%3Cspan%20class=%22dateCreated%22%3E12/01/2011%3C/span%3E%20%3Cspan%20style=%22color:#C5D0DD;%22%3E%20|%20%3C/span%3E%20Due%20Date:%20%3Cspan%20class=%22dueDate%22%3E01/01/2012%3C/span%3E%3C/strong%3E%3C/div%3E%3Cdiv%20style=%22clear:both;%22%3E%3C/div%3E%3Cdiv%20id=%22table-invoice-result%22%3E%3Ctable%20class=%22widefat%22%3E%3Ctbody%3E%3Ctr%3E%3Ctd%3EQuantity%3C/td%3E%3Ctd%3EDescription%3C/td%3E%3Ctd%3ERate%3C/td%3E%3Ctd%3EAmount%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E8%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3EROSS%20Server%20Fees:%20TESTING3%20%28December%2016th%202011-January%2015th%202012%29%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E$79.99%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E$639.92%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E12%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3EROSS%20Server%20Fees:%20TESTING3%20%28December%2016th%202011-January%2015th%202012%29%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E$79.99%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E$959.88%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E10%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$799.90%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%20style=%22background-color:white;%22%3E1%3C/td%3E%3Ctd%20style=%22background-color:white;text-align:left;%22%3ECustomer%20Credit:%20Server%20Fee%20Credit%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3Ctd%20style=%22background-color:white;%22%3E%3Cfont%20color=%22RED%22%3E-$79.99%3Cfont%3E%3C/font%3E%3C/font%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%3ESales%20Tax%3C/td%3E%3Ctd%20class=%22salestax%22%3E$0.00%3C/td%3E%3Ctd%3E%3C/td%3E%3Ctd%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%3E%3Cstrong%3ETotal%3C/strong%3E%3C/td%3E%3Ctd%20class=%22total%22%20style=%22font-weight:bold;%22%3E$0.00%3C/td%3E%3Ctd%3E%3C/td%3E%3Ctd%3E%3C/td%3E%3C/tr%3E%3Ctr%3E%3Ctd%3E%3C/td%3E%3Ctd%20class=%22date_paid_status%22%20style=%22font-size:%2020pt;%20color:darkblue;%20font-weight:bold;%22%3EPAID%2012/01/2011%3C/td%3E%3Ctd%3E%3C/td%3E%3Ctd%3E%3C/td%3E%3C/tr%3E%3C/tbody%3E%3C/table%3E%3C/div%3E%3Cbr%3E%3Ci%3E*%20Paper%20Checks%20are%20not%20accepted.%20Any%20paper%20checks%20received%20will%20be%20converted%20into%20E-Checks%20and%20destroyed.%3C/i%3E
My problem is if I try to echo this one, I'm not getting all the result. This is how I echo it.
$html = <<<EOD
{$_GET['html']}
EOD;
echo $html;
This are only the results I have when I echoed this:
<div class="invoice-logo" style="float:left;margin-bottom:15px;"><img src="https://myurl/account/images/invoice_logo.gif" title="Test Title"></div><div style="clear:both"></div><h3 class="invoiceNum" style="padding:0px;font-size:25px;"><strong>Invoice
As you can see, it cuts off after the code <strong>Invoice
Any ideas why this is happening. Any help would be greatly appreciated and rewarded!
Thanks!
You are doing something wrong.
HTML is a part of the program code, and shouldn't be sent to and fro between server and client.
Instead of that, only raw data should be recieved from client, then formatted on the server side and then resulting HTML have to be sent to client.
See http://www.boutell.com/newfaq/misc/urllength.html and Is there a limit to the length of a GET request?
You're much better off using curl to get the contents of the URL in PHP (if you're trying to get the HTML from a standard website), or using POST (if you're passing the HTML into the PHP file directly).
If you need the html to be inside a GET request, use base64_encode(). After submitting it, you can decode the html by running base64_decode($_GET['html']).

How do I use external JSON...?

spent a few hours trying to figure this out, but cannot for the life of me figure out what's going wrong.
All I'm trying to do is load this:
https://recruit.zoho.com/ats/EmbedResult.hr?jodigest=2cV.Sr2As6VxhLMxQGuTNij*g.Fb3J7ysduDs.AC9sU-&atslocale=en_GB&rawdata=json
which I believe is json, into either javascript/jquery or php and use the data.
I've looked into jsonp, followed some tutorials, used some demos as templates and just can't get the above data to work.
If anyone can shed some light it would be much appreciated. It really shouldn't be this complicated, but I don't know what's going wrong.
Yep, that's JSON. The site may not support JSONP, so you're gonna have to use PHP to do this.
This is untested, but should work.
<?php
$url = 'https://recruit.zoho.com/ats/EmbedResult.hr?jodigest=2cV.Sr2As6VxhLMxQGuTNij*g.Fb3J7ysduDs.AC9sU-&atslocale=en_GB&rawdata=json';
$JSON = file_get_contents($url);
// echo the JSON (you can echo this to JavaScript to use it there)
echo $JSON;
// You can decode it to process it in PHP
$data = json_decode($JSON);
var_dump($data);
?>
JSONP relies on the server to return a JSONP formatted response. Basically, to use JSONP the server needs to return a JSON string wrapped in a function invocation ({"foo":1} becomes func({"foo":1})).
As the server your using doesn't return a JSONP response, you cannot use JSONP, you can only use JSON.
This is a shame, as JSON cannot be used x-domain due to the same origin policy (SOP). Therefore, the only option you have is to use a proxy server, which retrieves the JSON from the server, and either gives it to you in JSONP (see Yahoo Pipes), or which is on the same domain as the requested page (write a simple PHP script to get the file using file_get_contents() and then echo the output), in which case it can return the JSON.
I breifly looked at the requirements and it looks like you need an API key as well as an account. I saw that the site provides services for XML and JSON only. It looks to be fairly well documented.

How can i make flexible XML data files for other websites?

I would like to know how can i give other website parsers an xml file or response based on arguments they request?
For example i have show_data.php file that can take range of params and then apply it to mysql query and then form valid xml 1.0 string.
So by this point i have finished with data fetching + xml formating based on request params.
Now how would i share that xml with other websites for their xml parsers?
Do i simply output my xml string in php file with appropriate headers or somehow else?
Example:
1)www.example.com request www.mypage.com/show_data.php?show=10
2)www.mypage.com/show_data.php send xml data back to www.example.com
It's really hard to explain since i have not worked with xml and stuff before. Hope it makes some sense.
Thanks.
Well, when example.com does the initial request, your page will process it and return the xml as the result. There's nothing special that you'll need to do.
$xml = "";
// process the xml (build it - do what you need to do)
// returning the xml to the requester
header ("Content-Type:text/xml");
echo $xml;

Categories