PHP - 不使用SOAP发送POST?

时间:2015-10-25 20:37:10

标签: php post soap soap-client roblox

This PHP code使用SoapClient工作。

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

它回应了一个数字。

我计划在x10hosting(或任何其他10分钟cron的免费网络主机)上执行此操作,x10hosting不支持SoapClient。

那么如果不使用Soap会怎么写?

编辑: 所以我也尝试过这个并没有用。

<?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);

?>

1 个答案:

答案 0 :(得分:1)

对于该特定呼叫,您可以使用CURL,请参阅下文。对于更广泛的SOAP请求,您可能希望查找库以替换缺少的SoapClient(请参阅您提问中的注释)。

使用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");
...

或者只是使用其他答案:PHP + curl, HTTP POST sample code?