PHP SOAP请求不工作

PHP SOAP请求不工作,php,soap,Php,Soap,您好,我是webservice的新手,在php中使用下面的代码,我试图发出soap请求,如下面的XML所示,但它说 错误 HTTP错误:不支持的HTTP响应状态405方法不允许(soapclient->response包含响应的内容) 问题。 1) 如何传递标题 2) 如何传递请求 我在这里使用了nusoap,但如果您有soap,也会邀请您使用php类解决方案 <?php error_reporting(E_ALL); require("../lib/nusoa

您好,我是webservice的新手,在php中使用下面的代码,我试图发出soap请求,如下面的XML所示,但它说 错误

HTTP错误:不支持的HTTP响应状态405方法不允许(soapclient->response包含响应的内容)

问题。 1) 如何传递标题 2) 如何传递请求

我在这里使用了nusoap,但如果您有soap,也会邀请您使用php类解决方案

    <?php

    error_reporting(E_ALL);


   require("../lib/nusoap.php");

error_reporting(E_ALL ^ E_NOTICE);
$ERROR_MSG = '';

$s_WSPROTOCOL = 'http';
$s_WSHOSTNAME = '###.###.###.##';
$s_WSPORT = ':8080';
$s_WSPATHNAME = 'ows_ws_51/Availability.asmx?WSDL';         
$s_WSTIPOOP = 'FetchCalendar';

$parameters['StayDateRange'] = array('StartDate' => '2013-10-01','EndDate' => '2013-10-10');


echo $s_WSTIPOOP."<br />";
echo $s_WSPROTOCOL."://".$s_WSHOSTNAME.$s_WSPORT."/".$s_WSPATHNAME."<br /><br /><br />";     
$client = new nusoap_client($s_WSPROTOCOL."://".$s_WSHOSTNAME.$s_WSPORT."/".$s_WSPATHNAME, true);

$result = $client->call($s_WSTIPOOP, $parameters);

if ($client->fault) {

echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2><pre>'; 
print_r($result); echo '</pre>';

} else {

$err = $client->getError();
if ($err) {

echo '<h2>Error</h2><pre>' . $err . '</pre>';

} else {
echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';
}
}

echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';

    ?>

XML


2013-10-01
2013-10-10
发布Url:http://000.000.000.00:8080/ows_ws_51/Availability.asmx 
Soap操作:http://webservices.test.com/ows/5.1/Availability.wsdl#FetchCalendar

您似乎不必发送凭据,这将返回一个应答:

有关该主题的更多信息,请参见:

===

下面是要执行该方法时的soapui响应


?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?

如果我将其与您的设置进行比较,您发送的选项和响应不提供用户凭据。这让我觉得你犯了一个错误,不允许你使用这种方法。从提供您的凭据开始。

您似乎不必发送凭据,这将返回一个应答:

有关该主题的更多信息,请参见:

===

下面是要执行该方法时的soapui响应


?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?

如果我将其与您的设置进行比较,您发送的选项和响应不提供用户凭据。这让我觉得你犯了一个错误,不允许你使用这种方法。从提供您的凭据开始。

您能给我一个示例代码,说明您是如何传递此标头的吗?未定义变量:ns$ns是名称空间,我想您需要
http://webservices.micros.com/og/4.3/Availability/
名称空间。查看wsdl
我已经更改了我的代码,它现在显示,
HTTP内容类型“UTF-8”中的错误字符集与XML声明“iso-8859-1”中的编码不匹配。
试试:$soap=new SoapClient('',数组(“trace”=>1,“exception”=>0,“encoding”=>iso-8859-1');你能给我看一个你如何传递这个头的示例代码吗?未定义的变量:ns$ns是名称空间,我想你需要
http://webservices.micros.com/og/4.3/Availability/
名称空间。查看wsdl
我已经更改了我的代码,它现在显示,
HTTP内容类型“UTF-8”中的错误字符集与XML声明“iso-8859-1”中的编码不匹配。
试试:$soap=new SoapClient('',数组(“trace”=>1,“exception”=>0,“encoding”=>iso-8859-1');可能相关(相同Web服务):可能相关(相同Web服务):
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
    <OGHeader transactionID="005435" timeStamp="2008-12-09T13:26:56.4056250-05:00" xmlns="http://webservices.test.com/og/4.3/Core/">
      <Origin entityID="OWS" systemType="WEB" />
      <Destination entityID="WEST" systemType="ORS" />
    </OGHeader>
  </soap:Header>
  <soap:Body>
    <FetchCalendarRequest xmlns:a="http://webservices.test.com/og/4.3/Availability/" xmlns:hc="http://webservices.test.com/og/4.3/HotelCommon/" xmlns="http://webservices.test.com/ows/5.1/Availability.wsdl">
      <HotelReference chainCode="AXA" hotelCode="AXAMUM" />
      <StayDateRange>
        <hc:StartDate>2013-10-01</hc:StartDate>
        <hc:EndDate>2013-10-10</hc:EndDate>
      </StayDateRange>
      <GuestCount>
        <hc:GuestCount ageQualifyingCode="ADULT" count="1" />
        <hc:GuestCount ageQualifyingCode="CHILD" count="0" />
      </GuestCount>
    </FetchCalendarRequest>
  </soap:Body>
</soap:Envelope>


    Post Url :http://000.000.000.00:8080/ows_ws_51/Availability.asmx 
Soap Action :  http://webservices.test.com/ows/5.1/Availability.wsdl#FetchCalendar
<?php
$soap = new SoapClient('http://webservices.micros.com/ows/5.1/Availability.wsdl', array("trace" => 1, "exception" => 0));

var_dump($soap->FetchCalendar(array(
    'StayDateRange' => array(
        'StartDate' => '2013-10-01',
        'EndDate' => '2013-10-10'
    )
)));
<?php
$headerbody = array('Origin' => 'foo',
                    'Destination' => 'bar');
$header = new SOAPHeader($ns, 'RequestorCredentials', $headerbody);
$soap->__setSoapHeaders($header);
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:core="http://webservices.micros.com/og/4.3/Core/" xmlns:ava="http://webservices.micros.com/ows/5.1/Availability.wsdl" xmlns:hot="http://webservices.micros.com/og/4.3/HotelCommon/">
   <soapenv:Header>
      <core:OGHeader transactionID="?" authToken="?" timeStamp="?" primaryLangID="E" channelValidation="true" terminalID="?">
         <core:Origin entityID="?" organizationID="?" systemType="?"/>
         <core:Destination entityID="?" organizationID="?" systemType="?"/>
         <!--Optional:-->
         <core:Intermediaries>
            <!--1 or more repetitions:-->
            <core:EndPoint entityID="?" organizationID="?" systemType="?"/>
         </core:Intermediaries>
         <!--Optional:-->
         <core:Authentication>
            <core:UserCredentials>
               <core:UserName>?</core:UserName>
               <core:UserPassword>?</core:UserPassword>
               <core:Domain>?</core:Domain>
               <!--Optional:-->
               <core:SecurityId>?</core:SecurityId>
            </core:UserCredentials>
            <!--Optional:-->
            <core:Licence>
               <!--Optional:-->
               <core:Key>?</core:Key>
            </core:Licence>
         </core:Authentication>
      </core:OGHeader>
   </soapenv:Header>
   <soapenv:Body>
      <ava:FetchCalendarRequest>
         <ava:HotelReference chainCode="?" hotelCode="?">?</ava:HotelReference>
         <ava:StayDateRange>
            <hot:StartDate>?</hot:StartDate>
            <!--You have a CHOICE of the next 2 items at this level-->
            <hot:EndDate>?</hot:EndDate>
            <hot:Duration>?</hot:Duration>
         </ava:StayDateRange>
         <!--Optional:-->
         <ava:GuestCount isPerRoom="?">
            <!--1 or more repetitions:-->
            <hot:GuestCount ageQualifyingCode="?" otherAgeQualifyingCode="?" age="?" count="?"/>
         </ava:GuestCount>
         <!--Optional:-->
         <ava:RatePlanCode>?</ava:RatePlanCode>
         <!--Optional:-->
         <ava:RoomTypeCode>?</ava:RoomTypeCode>
         <!--Optional:-->
         <ava:BlockCode>?</ava:BlockCode>
         <!--Optional:-->
         <ava:CorporateCode>?</ava:CorporateCode>
         <!--Optional:-->
         <ava:PromotionCode>?</ava:PromotionCode>
         <!--Optional:-->
         <ava:NumberOfNights>?</ava:NumberOfNights>
         <!--Optional:-->
         <ava:RestrictedMode>?</ava:RestrictedMode>
         <!--Optional:-->
         <ava:InventoryMode>?</ava:InventoryMode>
      </ava:FetchCalendarRequest>
   </soapenv:Body>
</soapenv:Envelope>