0

I'm strugling with this for a couple of days now. I read articles and other stuff and I can't find a solution. So. I'm working on a ski resort website based on Wordpress which has to read data from ski conditions website. The owners of the API are sending me XML data via URL: http://snezni-telefon.si/svrh_xml_test.php and they are telling me to read it with POST request. I tried everything from file_get_contents to simplexml requests and nothing works. So my question is:

How to read XML data generated in PHP file from another server with $_POST request?

Thank you!

EDIT: I tried simplexml_load_file, wp_remote_post and file_get_contents.

EDIT #2: So after going back and forth with my client they told me everything that they are doing with the script. So they have a script which contains and XML in string form, which is calling my script in which I have to get $_POST['XML'] variable. So if I understand correctly I just have to parse that $_POST variable which is simple and logical but I can't seem to make it work. Any suggestions?

janip
  • 19
  • 7
  • 3
    You need to show us what you've tried. You could also start by searching for: "How to make a POST request with PHP"? – M. Eriksson Nov 14 '17 at 13:34
  • Either it's a field in $_POST (maybe just print `var_export($_POST, true)` to a log file if you don't know the exact info they send you) or they're sending the XML as the post body directly, in which case you can use [php://input](http://php.net/manual/de/wrappers.php.php#wrappers.php.input). – janh Nov 14 '17 at 13:36
  • 2
    Btw, are they _sending_ the data (they post to your website) or are you trying to _fetch_ the data (making a post request to _their_ api)? There's a _huge_ difference. – M. Eriksson Nov 14 '17 at 13:37
  • I'm trying to make a post request to them. They only sent me the link which is in the question and that's it and told me to make a POST request – janip Nov 14 '17 at 13:40
  • 1
    Possible duplicate of [How do I send a POST request with PHP?](https://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php) - You still need to show us what you actually tried. – M. Eriksson Nov 14 '17 at 13:41
  • I edited the question and checked out the link you gave me. So I have to get the XML data from $_POST variable: $_POST['XML']. – janip Nov 14 '17 at 13:54
  • Forgot to mention this: the endpoint read must be `echo htmlspecialchars($_POST["XML"]);` – janip Nov 14 '17 at 14:26

0 Answers0