Hi there,
I'ver tried to build my first API from a very basic example I saw online. Since it didn't work so well initially, I copied the exact code in the end, tried again, but no cigar. I'm not sure what could be wrong here, but I do get a server 500 message when I try to load the client.
However, the API URL seems to work fine: http://dev.badgercomp.com/api/testapi.php
Here is the server code:
<?php
function getStockQuote($symbol) {
include('dbconnection.php');
$query = "SELECT stock_price FROM stockprices "
. "WHERE stock_symbol = '$symbol'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
return $row['stock_price'];
}
require('nusoap.php');
$server = new soap_server();
$server->configureWSDL('stockserver', 'urn:stockquote');
$server->register("getStockQuote",
array('symbol' => 'xsd:string'),
array('return' => 'xsd:decimal'),
'urn:stockquote',
'urn:stockquote#getStockQuote');
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
And here is the client code:
<?php
require('nusoap.php');
$c = new soapclient('http://dev.badgercomp.com/api/testapi.php');
$stockprice = $c->call('getStockQuote',
array('symbol' => 'ABC'));
echo "The stock price for 'ABC' is $stockprice.";
?>
This all seems easy enough, so I can't understand why it won't work. Any advice?