0

This PHP code works using SoapClient.

$client = new SoapClient("http://www.roblox.com/Marketplace/EconomyServices.asmx?WSDL");
$response = $client->GetEstimatedTradeReturnForTickets(array("ticketsToTrade" => 1000));
echo $response->GetEstimatedTradeReturnForTicketsResult;

It echoes a number.

I plan on doing this on x10hosting (or any other free web host with 10 minute cron) and x10hosting doesn't support SoapClient.

So how would this be written without using Soap?

EDIT: So I've also tried this and it didn't work.

<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.roblox.com/Marketplace/EconomyServices.asmx/GetEstimatedTradeReturnForRobux");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,array("robuxToTrade" => 1000));

// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

echo $server_output

curl_close ($ch);

?>
GShocked
  • 3,106
  • 7
  • 22
  • 42
  • 1
    Haven't tested, but [this question](http://stackoverflow.com/questions/4430/how-to-easily-consume-a-web-service-from-php) seems to list some alternatives. – Mr Lister Oct 25 '15 at 20:59
  • 1
    copy that URL into a browser and see what happens. Yes, you can send a POST without using using xoapclient, its even relatively simple to create XML, but creating XML which confrorms the current DTD used by the webservice and parsing the response is a lot more difficult. There are soap client *written* in PHP (but I've ot used any of them) – symcbean Oct 25 '15 at 21:19

1 Answers1

1

For that specific call you can use CURL, see below. For more extensive SOAP requests you might want to look for a library to replace the missing SoapClient (see the comments under your question).

Example using CURL:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.roblox.com/Marketplace/EconomyServices.asmx/GetEstimatedTradeReturnForRobux");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "ticketsToTrade=1000");
...

Or just use other answers: PHP + curl, HTTP POST sample code?

Community
  • 1
  • 1
jso
  • 461
  • 5
  • 13
  • I tried your code, while adding `$response = curl_exec($ch);` and `echo $response;`, but it only returns an Internal Server Error 500. I tried changing the URL to `...ReturnForTickets` and that didn't work. I also tried changing the input fields to `robuxToTrade` and that didn't work either. – GShocked Oct 26 '15 at 18:41
  • Does the code return _Internal Server Error 500_ why trying to run it or is this the result of the call? In first case, you are missing a semicolon after `echo $server_output`. If the latter then browse the documentation.. it'd be just guessing from me. – jso Oct 26 '15 at 19:02
  • I fixed the missing semicolon, still chrome returns an e 500. The server isn't delivering a HTML formatted error 500 page, Google chrome is. – GShocked Oct 26 '15 at 19:30