0

Some server send me data (XML or Json) on my url www.mydomain.com/url by curl. How can I receive such data? I tried make request on that url:

$body = @file_get_contents('php://input');

but in variable is empty string. Is that correct way to do that or is not?

tomasr
  • 485
  • 1
  • 8
  • 24
  • You can refer this solution : http://stackoverflow.com/questions/12781876/get-file-content-via-php-curl – NikuNj Rathod Jul 01 '16 at 08:46
  • @NikunjRathod That is not what the OP is trying to do. – arkascha Jul 01 '16 at 08:47
  • Can you please show _how_ that data is contained in the request you receive? – arkascha Jul 01 '16 at 08:47
  • @NikunjRathod It is not same thing. I don't need read dat from another server, but from my url, where another server post data. – tomasr Jul 01 '16 at 08:49
  • @arkascha I do not receive nothing, just empty string. I do not understand to this use of posting data. Similar way works confirmation of online paying by card. Payment service sends confirmation about payment on your url and you have to proccess it. – tomasr Jul 01 '16 at 08:54
  • If you _really_ receive nothing, then there is nothing you can do. But I assume what you mean is: I _do_ receive something, but do not know how to access it. So you have to find out _how_ that data is sent to your service, in what structure. I assume you have some form of definition or documentation of that request pushing data to you. A simple start is to look at the request entry in your http servers access lock file. It will show you the type and size of the request at least. As a last option you could also use a simple network sniffer and examine the data. – arkascha Jul 01 '16 at 08:58
  • Please try this solution for : http://stackoverflow.com/questions/11079135/how-to-post-json-data-with-php-curl – NikuNj Rathod Jul 01 '16 at 08:59
  • And it might be that you try a completely wrong approach: you cannot somehow access data that "is sent to a URL" on your service from another script. That URL that is requested has to process the incoming data or store it for later processing. So something like `https://api.example.org/accept_data.php` which is the URL that remote service is pushing the data to. – arkascha Jul 01 '16 at 09:01

1 Answers1

0

If you are getting the data as a file , then you have to give the code like

$file_name = $_FILES[];

or it was some json data ,

$data=$_POST[];or $_GET[]; according to get or post method.

Then move the file to some location in your project. If it has a name , then you can add the below code

$tmp_name = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
move_uploaded_file($tmp_name, 'your file moving path'.$file_name);
Prakash P
  • 342
  • 1
  • 9