【问题标题】:PHP - Sending POST without using SOAP?PHP - 在不使用 SOAP 的情况下发送 POST?
【发布时间】:2016-01-24 21:47:11
【问题描述】:

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

?>

【问题讨论】:

  • 尚未测试,但this question 似乎列出了一些替代方案。
  • 将该 URL 复制到浏览器中,看看会发生什么。是的,您可以在不使用 xoapclient 的情况下发送 POST,创建 XML 甚至相对简单,但是创建与 web 服务使用的当前 DTD 相符的 XML 并解析响应要困难得多。 PHP中有soap客户端编写(但我一个都没用过)

标签: php post soap soap-client roblox


【解决方案1】:

对于该特定调用,您可以使用 CURL,见下文。对于更广泛的 SOAP 请求,您可能需要寻找一个库来替换缺少的 SoapClient(请参阅您问题下的 cmets)。

使用 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?

【讨论】:

  • 我尝试了您的代码,同时添加了$response = curl_exec($ch);echo $response;,但它只返回内部服务器错误500。我尝试将URL 更改为...ReturnForTickets,但没有成功。我还尝试将输入字段更改为robuxToTrade,但这也不起作用。
  • 代码是否返回Internal Server Error 500 为什么要运行它或者这是调用的结果?在第一种情况下,echo $server_output 后面缺少分号。如果是后者然后浏览文档..这只是我的猜测。
  • 我修复了丢失的分号,但 chrome 仍然返回 e 500。服务器没有提供 HTML 格式的错误 500 页面,Google chrome 是。
猜你喜欢
  • 2015-11-06
  • 1970-01-01
  • 2012-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-28
  • 2023-03-19
  • 1970-01-01
相关资源
最近更新 更多