Reputation: 47
I'm a bit new to web services. I followed this tutorial and built a web service: http://davidwalsh.name/web-service-php-mysql-xml-json.
However, when I try to call to the web service using some parameters, e.g.
http://example.com/web-service.php?user=2&num=10
it is going to that page and shows the result. What I need is to get results without going to the site. I know this is possible by using Ajax, but I need to know is there any other way we can accomplish this? As the headers are using
header('Content-type: application/json');
can't we get data without going to the web service page?
Upvotes: 2
Views: 11690
Reputation: 5121
<?php
include 'Connection.php';
include 'class.phpmailer.php';
include 'class.smtp.php';
$entityBody = file_get_contents("php://input");
$data=json_decode($entityBody, TRUE);
?>
Upvotes: 0
Reputation: 3021
By "going to the webservice page" I assume you mean in your browser? @bardiir points out that you can use any http client to get this data.
In PHP, you could simply do a
$json = file_get_contents("http://mydomain.com/web-service.php?user=2&num=10"); // this will require php.ini to be setup to allow fopen over URLs
$data = json_decode($json);
var_dump($data)
and you would have the web service information as an array that you could parse and act upon.
If you can clarify further what it is you want to accomplish, I could help out more.
Upvotes: 1
Reputation: 14782
Well you can download the data using wget or curl too. That always depends on what you try to accomplish by using the data.
Upvotes: 0