关于使用SOAP& amp;提交数据到API的非常基本的问题PHP

时间:2009-11-19 19:25:51

标签: php api soap

在我提出问题之前,我要感谢所有关于堆栈溢出的人。我真的很惊讶每个人都有多大帮助,以及在过去一年左右我在困惑时提出问题时我学到了多少。

我正在尝试将此API上的recordSale函数用于与我的工作有关的人,这是一种记录销售的方式(因此名称):

网址:https://secure.directtrack.com/api/soap.php# wsdl:https://secure.directtrack.com/api/soap.php?wsdl

名称:recordSale 绑定:DirectTrackWebServicesBinding 端点:http://secure.directtrack.com/api/soap.php SoapAction:http://secure.directtrack.com/api/soap.php/recordSale 风格:rpc 输入:   使用:编码   命名空间:http://soapinterop.org//   encodingStyle:http://schemas.xmlsoap.org/soap/encoding/   message:recordSaleRequest   部分:     client:xsd:string     密码:xsd:string     order_id:xsd:string     sale_amount:xsd:double     campaign_id:xsd:int

输出:   使用:编码   命名空间:http://soapinterop.org//   encodingStyle:http://schemas.xmlsoap.org/soap/encoding/   消息:recordSaleResponse   部分:     return:xsd:int

命名空间:http://soapinterop.org// 运输:http://schemas.xmlsoap.org/soap/http

所以我试图为此设置php,我写道:

$client2 = new SoapClient("http://secure.directtrack.com/api/soap.php?wsdl", array('trace'=> true));
$results2 = $client2->recordSale(array(
                                       "client" => 'my work's client #', 
                                       "password" => "password",
                                       "order_id"  => "2",
                                       "sale_amount"  => "1000",
                                       "campaign_id"  => "16",
                                       "affiliate_code"  => "CD35",
                                       "date"  => "2009-11-17",
                                       "sale_status"  => "",
                                       "optional_info"  => "fsq2",
                                       "misc"  => "9",
                                       "record_lead"  => "1"));
echo "<pre>";
        print_r($results2);
echo "</pre>";

打印的返回值是数字“1”。问题是,如果我更改密码或省略必填字段,则此“1”不会更改。我是以完全错误的方式解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

看起来你在那里有一个单引号

'my work's client #'

......应该是:

"my work's client #"

其次,您应该使用调试工具(我使用eclipse php进行调试,但有几个包括netbeans)。您将看到有关调试器的更多信息。

最后,您可以通过以下方式查看请求和响应的实际XML:

$lastRequest = $client2->__getLastRequest();
$lastResponse = $client2->__getLastResponse();

...因为你已经开启了踪迹。

答案 1 :(得分:0)

您能否在代码中添加一些调试语句,以查看在线上发生的事情

$client2 = new SoapClient("http://secure.directtrack.com/api/soap.php?wsdl", array(
    'trace'=> true
));
$results2 = $client2->recordSale(array(
    "client" => // ...
));
echo "<pre>";
var_dump($client2-> __getLastRequestHeaders());
var_dump($client2-> __getLastRequest());
var_dump($client2-> __getLastResponseHeaders());
var_dump($client2-> __getLastResponse());
var_dump($results2);
echo "</pre>";

这将使您深入了解正在生成的SOAP请求以及从服务器返回的SOAP响应。