Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP调用SOAP API_Php_Api_Soap_Call - Fatal编程技术网

用PHP调用SOAP API

用PHP调用SOAP API,php,api,soap,call,Php,Api,Soap,Call,这项工作已经进行了一周了。执行此代码时遇到问题。我想通过SOAP检索数据并在PHP中使用它。我的问题是,我在发送“RequesterCredentials”时遇到了麻烦 我将展示xml代码,以便大家都能看到我试图发送的信息,然后是我正在使用的PHP代码 XML示例代码 POST /AuctionService.asmx HTTP/1.1 Host: apiv2.gunbroker.com Content-Type: text/xml; charset=utf-8 Content-Length:

这项工作已经进行了一周了。执行此代码时遇到问题。我想通过SOAP检索数据并在PHP中使用它。我的问题是,我在发送“RequesterCredentials”时遇到了麻烦

我将展示xml代码,以便大家都能看到我试图发送的信息,然后是我正在使用的PHP代码

XML示例代码

POST /AuctionService.asmx HTTP/1.1
Host: apiv2.gunbroker.com
Content-Type: text/xml; charset=utf-8
Content-Length: 200
SOAPAction: "GunBrokerAPI_V2/GetItem"

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Header>
   <RequesterCredentials xmlns="GunBrokerAPI_V2">
     <DevKey>devkey</DevKey>
     <AppKey>appkey</AppKey>
   </RequesterCredentials>
 </soap:Header>
 <soap:Body>
<GetItem xmlns="GunBrokerAPI_V2">
  <GetItemRequest>
    <ItemID>312007942</ItemID>
    <ItemDetail>Std</ItemDetail>
  </GetItemRequest>
</GetItem>

我不确定问题是我发送SOAPHeader的方式还是我误解了语法。非常感谢您的帮助。

使用对象而不是关联数组作为标题:

$item = new stdClass;
$item->ItemID = '312343077';
$item->ItemDetail = 'Std';

$result = $client->GetItem(array('GetItemRequest' => $item));
您可能面临的下一个问题是在
GetItem
调用时,您也需要对象,包装在关联数组中:


code
之前大喊大叫是非常令人不安的。当ws请求
RequesterCredentials值时,您正在发送
RequesterCredentials
,而ws只是想对完全相同的内容进行注释。阅读错误消息,其中包含一些信息
RequesterCredentialsValue
缺失,并且代码中:未设置。因此,在我看来,错误消息看起来不错。不幸的是,更改为RequesterCredentialsValue会得到相同的结果。它似乎不是随调用一起发送的,也许我在SoapHeader的第一个参数中使用的URL没有意义?做得很好。我把这个代码放进去了,它就像一个符咒。非常感谢!
stdClass Object
(
[GetItemResult] => stdClass Object
    (
        [Timestamp] => 2012-11-07T18:17:31.9032903-05:00
        [Ack] => Failure
        [Errors] => stdClass Object
            (
                [ShortMessage] => GunBrokerAPI_V2 Error Message : [GetItem]
You must fill in the 'RequesterCredentialsValue' SOAP header for this Web Service method.
                [ErrorCode] => 1
            )
// the rest if just an array of empty fields that I could retrieve if i wasnt havng problems.
$obj = new stdClass();

$obj->AppKey = $appkey;
$obj->DevKey = $devkey;

$header = new SoapHeader('GunBrokerAPI_V2','RequesterCredentials',$obj,0);
$item = new stdClass;
$item->ItemID = '312343077';
$item->ItemDetail = 'Std';

$result = $client->GetItem(array('GetItemRequest' => $item));